30 #include "interpreter.h"
31 #include "operations.h"
32 #include "math_object.h"
34 #include "math_object.lut.h"
37 #define M_PI 3.14159265358979323846
41 #define signbit(x) ((x) < 0.0 || IS_NEGATIVE_ZERO(x))
48 const ClassInfo MathObjectImp::info = {
"Math", 0, &mathTable, 0 };
81 MathObjectImp::MathObjectImp(
ExecState * ,
82 ObjectPrototypeImp *objProto)
85 unsigned int seed = time(NULL);
92 return lookupGet<MathFuncImp, MathObjectImp, ObjectImp>( exec, propertyName, &mathTable, this );
95 Value MathObjectImp::getValueProperty(
ExecState *,
int token)
const
124 fprintf( stderr,
"[math_object] Internal error in MathObjectImp: unhandled token %d\n", token );
133 MathFuncImp::MathFuncImp(
ExecState *exec,
int i,
int l)
135 static_cast<
FunctionPrototypeImp*>(exec->lexicalInterpreter()->builtinFunctionPrototype().imp())
139 putDirect(lengthPropertyName, l, DontDelete|ReadOnly|DontEnum);
142 bool MathFuncImp::implementsCall()
const
149 double arg = args[0].toNumber(exec);
150 double arg2 = args[1].toNumber(exec);
154 case MathObjectImp::Abs:
155 result = ( arg < 0 || arg == -0) ? (-arg) : arg;
157 case MathObjectImp::ACos:
158 result = ::acos(arg);
160 case MathObjectImp::ASin:
161 result = ::asin(arg);
163 case MathObjectImp::ATan:
164 result = ::atan(arg);
166 case MathObjectImp::ATan2:
167 result = ::atan2(arg, arg2);
169 case MathObjectImp::Ceil:
170 result = ::ceil(arg);
172 case MathObjectImp::Cos:
175 case MathObjectImp::Exp:
178 case MathObjectImp::Floor:
179 result = ::floor(arg);
181 case MathObjectImp::Log:
184 case MathObjectImp::Max: {
185 unsigned int argsCount = args.
size();
187 for (
unsigned int k = 0 ; k < argsCount ; ++k ) {
188 double val = args[k].toNumber(exec);
194 if ( val > result || (val == 0 && result == 0 && !signbit(val)) )
199 case MathObjectImp::Min: {
200 unsigned int argsCount = args.
size();
202 for (
unsigned int k = 0 ; k < argsCount ; ++k ) {
203 double val = args[k].toNumber(exec);
209 if ( val < result || (val == 0 && result == 0 && signbit(val)) )
214 case MathObjectImp::Pow:
216 if (KJS::isNaN(arg2))
218 #ifndef APPLE_CHANGES
222 else if (KJS::isNaN(arg) && arg2 != 0)
224 #ifndef APPLE_CHANGES
225 else if (::fabs(arg) > 1 && KJS::isPosInf(arg2))
227 else if (::fabs(arg) > 1 && KJS::isNegInf(arg2))
230 else if (::fabs(arg) == 1 && KJS::isInf(arg2))
232 #ifndef APPLE_CHANGES
233 else if (::fabs(arg) < 1 && KJS::isPosInf(arg2))
235 else if (::fabs(arg) < 1 && KJS::isNegInf(arg2))
239 result = ::pow(arg, arg2);
241 case MathObjectImp::Random:
243 result = result / RAND_MAX;
245 case MathObjectImp::Round:
246 if (signbit(arg) && arg >= -0.5)
249 result = ::floor(arg + 0.5);
251 case MathObjectImp::Sin:
254 case MathObjectImp::Sqrt:
255 result = ::sqrt(arg);
257 case MathObjectImp::Tan:
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents...
Base class for all function objects.
Represents an primitive Number value.
The initial value of Function.prototype (and thus all objects created with the Function constructor) ...
Represents the current state of script execution.
Represents an Identifier for a Javascript object.