[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r9633: Fixes to Math class, cleanup
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r9633: Fixes to Math class, cleanup in as_value.cpp. |
Date: |
Fri, 22 Aug 2008 15:23:29 +0200 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 9633
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Fri 2008-08-22 15:23:29 +0200
message:
Fixes to Math class, cleanup in as_value.cpp.
modified:
libcore/as_value.cpp
libcore/asobj/Math_as.cpp
=== modified file 'libcore/as_value.cpp'
--- a/libcore/as_value.cpp 2008-08-21 14:30:29 +0000
+++ b/libcore/as_value.cpp 2008-08-22 13:23:29 +0000
@@ -1394,7 +1394,6 @@
// but that may just be a better compiler.
// Handle non-numeric values.
- // "printf" gives "nan", "inf", "-inf", so we check explicitly
if(isNaN(val))
{
return "NaN";
@@ -1429,9 +1428,7 @@
if (pos != std::string::npos) {
str.erase(pos + 1);
}
-
}
-
else
{
ostr << std::setprecision(15) << val;
@@ -1444,25 +1441,27 @@
if (pos != std::string::npos && str.at(pos + 2) == '0')
{
str.erase(pos + 2, 1);
}
-
}
+
+ return str;
+
}
- else
+
+ // Radix isn't 10
+
+ bool negative = (val < 0);
+ if ( negative ) val = -val;
+
+ double left = std::floor(val);
+ if ( left < 1 ) return "0";
+ while ( left != 0 )
{
- bool negative = (val < 0);
- if ( negative ) val = -val;
-
- double left = std::floor(val);
- if ( left < 1 ) return "0";
- while ( left != 0 )
- {
- double n = left;
- left = std::floor(left / radix);
- n -= (left * radix);
- str.insert(0, 1, (n < 10 ? ((int)n+'0') :
((int)n+('a'-10))));
- }
- if ( negative ) str.insert(0, 1, '-');
+ double n = left;
+ left = std::floor(left / radix);
+ n -= (left * radix);
+ str.insert(0, 1, (n < 10 ? ((int)n+'0') : ((int)n+('a'-10))));
}
+ if ( negative ) str.insert(0, 1, '-');
return str;
=== modified file 'libcore/asobj/Math_as.cpp'
--- a/libcore/asobj/Math_as.cpp 2008-08-18 23:53:04 +0000
+++ b/libcore/asobj/Math_as.cpp 2008-08-22 13:23:29 +0000
@@ -82,26 +82,18 @@
// All one-argument Math functions called with no args return NaN
//
+// If it is called with two arguments, the valueOf method
+// (i.e. to_number()) of the second method is called, but
+// not used. Strange, but true.
#define MATH_WRAP_FUNC1(funcname) \
as_value math_##funcname(const fn_call& fn) \
{ \
- double result; \
- if (fn.nargs < 1) result = NaN; \
- else { \
- double arg = fn.arg(0).to_number(); \
- result = std::funcname(arg); \
- } \
- return as_value(result); \
+ if (fn.nargs < 1) return as_value(NaN); \
+ if (fn.nargs == 2) fn.arg(1).to_number(); \
+ double arg = fn.arg(0).to_number(); \
+ return as_value(std::funcname(arg)); \
}
-// Dirty it is, but what's it for? All the functions used here are
-// in the standard cmath header, so there *ought* to be no need for
-// a hack.
-//#ifndef __GNUC__ //Some hacks are ugly and dirty, we call them 'fulhack'.
-//# undef TU_MATH_H
-//# include "tu_math.h"
-//#endif
-
MATH_WRAP_FUNC1(fabs)
MATH_WRAP_FUNC1(acos)
MATH_WRAP_FUNC1(asin)
@@ -140,11 +132,42 @@
}
MATH_WRAP_FUNC2_EXP(atan2, (std::atan2(arg0, arg1)))
-MATH_WRAP_FUNC2_EXP(max, (arg0 > arg1 ? arg0 : arg1))
-MATH_WRAP_FUNC2_EXP(min, (arg0 < arg1 ? arg0 : arg1))
MATH_WRAP_FUNC2_EXP(pow, (std::pow(arg0, arg1)))
+as_value
+math_min(const fn_call& fn)
+{
+ if (fn.nargs < 2) return as_value(NaN);
+
+ double arg0 = fn.arg(0).to_number();
+ double arg1 = fn.arg(1).to_number();
+
+ if (isNaN(arg0) || isNaN(arg1))
+ {
+ return as_value(NaN);
+ }
+
+ return as_value(std::min(arg0, arg1));
+
+}
+
+as_value
+math_max(const fn_call& fn)
+{
+ if (fn.nargs < 2) return as_value(NaN);
+
+ double arg0 = fn.arg(0).to_number();
+ double arg1 = fn.arg(1).to_number();
+
+ if (isNaN(arg0) || isNaN(arg1))
+ {
+ return as_value(NaN);
+ }
+
+ return as_value(std::max(arg0, arg1));
+}
+
// A couple of oddballs.
as_value
math_random(const fn_call& /* fn */)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r9633: Fixes to Math class, cleanup in as_value.cpp.,
Benjamin Wolsey <=