Bug 449522 - Context menu for HTML5 <video> elements. r=gavin, ui-r=boriss
[wine-gecko.git] / js / src / jsmath.cpp
blobea6bda8a9c7a07e84e2a1d0eedba14b6e670d2a9
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 * JS math package.
43 #include "jsstddef.h"
44 #include "jslibmath.h"
45 #include <stdlib.h>
46 #include "jstypes.h"
47 #include "jslong.h"
48 #include "prmjtime.h"
49 #include "jsapi.h"
50 #include "jsatom.h"
51 #include "jsbuiltins.h"
52 #include "jscntxt.h"
53 #include "jsversion.h"
54 #include "jslock.h"
55 #include "jsmath.h"
56 #include "jsnum.h"
57 #include "jsobj.h"
59 extern jsdouble js_NaN;
61 #ifndef M_E
62 #define M_E 2.7182818284590452354
63 #endif
64 #ifndef M_LOG2E
65 #define M_LOG2E 1.4426950408889634074
66 #endif
67 #ifndef M_LOG10E
68 #define M_LOG10E 0.43429448190325182765
69 #endif
70 #ifndef M_LN2
71 #define M_LN2 0.69314718055994530942
72 #endif
73 #ifndef M_LN10
74 #define M_LN10 2.30258509299404568402
75 #endif
76 #ifndef M_PI
77 #define M_PI 3.14159265358979323846
78 #endif
79 #ifndef M_SQRT2
80 #define M_SQRT2 1.41421356237309504880
81 #endif
82 #ifndef M_SQRT1_2
83 #define M_SQRT1_2 0.70710678118654752440
84 #endif
86 static JSConstDoubleSpec math_constants[] = {
87 {M_E, "E", 0, {0,0,0}},
88 {M_LOG2E, "LOG2E", 0, {0,0,0}},
89 {M_LOG10E, "LOG10E", 0, {0,0,0}},
90 {M_LN2, "LN2", 0, {0,0,0}},
91 {M_LN10, "LN10", 0, {0,0,0}},
92 {M_PI, "PI", 0, {0,0,0}},
93 {M_SQRT2, "SQRT2", 0, {0,0,0}},
94 {M_SQRT1_2, "SQRT1_2", 0, {0,0,0}},
95 {0,0,0,{0,0,0}}
98 JSClass js_MathClass = {
99 js_Math_str,
100 JSCLASS_HAS_CACHED_PROTO(JSProto_Math),
101 JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
102 JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
103 JSCLASS_NO_OPTIONAL_MEMBERS
106 static JSBool
107 math_abs(JSContext *cx, uintN argc, jsval *vp)
109 jsdouble x, z;
111 if (argc == 0) {
112 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
113 return JS_TRUE;
115 x = js_ValueToNumber(cx, &vp[2]);
116 if (JSVAL_IS_NULL(vp[2]))
117 return JS_FALSE;
118 z = fabs(x);
119 return js_NewNumberInRootedValue(cx, z, vp);
122 static JSBool
123 math_acos(JSContext *cx, uintN argc, jsval *vp)
125 jsdouble x, z;
127 if (argc == 0) {
128 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
129 return JS_TRUE;
131 x = js_ValueToNumber(cx, &vp[2]);
132 if (JSVAL_IS_NULL(vp[2]))
133 return JS_FALSE;
134 #if defined(SOLARIS) && defined(__GNUC__)
135 if (x < -1 || 1 < x) {
136 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
137 return JS_TRUE;
139 #endif
140 z = acos(x);
141 return js_NewNumberInRootedValue(cx, z, vp);
144 static JSBool
145 math_asin(JSContext *cx, uintN argc, jsval *vp)
147 jsdouble x, z;
149 if (argc == 0) {
150 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
151 return JS_TRUE;
153 x = js_ValueToNumber(cx, &vp[2]);
154 if (JSVAL_IS_NULL(vp[2]))
155 return JS_FALSE;
156 #if defined(SOLARIS) && defined(__GNUC__)
157 if (x < -1 || 1 < x) {
158 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
159 return JS_TRUE;
161 #endif
162 z = asin(x);
163 return js_NewNumberInRootedValue(cx, z, vp);
166 static JSBool
167 math_atan(JSContext *cx, uintN argc, jsval *vp)
169 jsdouble x, z;
171 if (argc == 0) {
172 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
173 return JS_TRUE;
175 x = js_ValueToNumber(cx, &vp[2]);
176 if (JSVAL_IS_NULL(vp[2]))
177 return JS_FALSE;
178 z = atan(x);
179 return js_NewNumberInRootedValue(cx, z, vp);
182 static JSBool
183 math_atan2(JSContext *cx, uintN argc, jsval *vp)
185 jsdouble x, y, z;
187 if (argc <= 1) {
188 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
189 return JS_TRUE;
191 x = js_ValueToNumber(cx, &vp[2]);
192 if (JSVAL_IS_NULL(vp[2]))
193 return JS_FALSE;
194 y = js_ValueToNumber(cx, &vp[3]);
195 if (JSVAL_IS_NULL(vp[3]))
196 return JS_FALSE;
197 #if defined(_MSC_VER)
199 * MSVC's atan2 does not yield the result demanded by ECMA when both x
200 * and y are infinite.
201 * - The result is a multiple of pi/4.
202 * - The sign of x determines the sign of the result.
203 * - The sign of y determines the multiplicator, 1 or 3.
205 if (JSDOUBLE_IS_INFINITE(x) && JSDOUBLE_IS_INFINITE(y)) {
206 z = js_copysign(M_PI / 4, x);
207 if (y < 0)
208 z *= 3;
209 return js_NewDoubleInRootedValue(cx, z, vp);
211 #endif
213 #if defined(SOLARIS) && defined(__GNUC__)
214 if (x == 0) {
215 if (JSDOUBLE_IS_NEGZERO(y)) {
216 z = js_copysign(M_PI, x);
217 return js_NewDoubleInRootedValue(cx, z, vp);
219 if (y == 0) {
220 z = x;
221 return js_NewDoubleInRootedValue(cx, z, vp);
224 #endif
225 z = atan2(x, y);
226 return js_NewNumberInRootedValue(cx, z, vp);
229 static JSBool
230 math_ceil(JSContext *cx, uintN argc, jsval *vp)
232 jsdouble x, z;
234 if (argc == 0) {
235 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
236 return JS_TRUE;
238 x = js_ValueToNumber(cx, &vp[2]);
239 if (JSVAL_IS_NULL(vp[2]))
240 return JS_FALSE;
241 z = ceil(x);
242 return js_NewNumberInRootedValue(cx, z, vp);
245 static JSBool
246 math_cos(JSContext *cx, uintN argc, jsval *vp)
248 jsdouble x, z;
250 if (argc == 0) {
251 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
252 return JS_TRUE;
254 x = js_ValueToNumber(cx, &vp[2]);
255 if (JSVAL_IS_NULL(vp[2]))
256 return JS_FALSE;
257 z = cos(x);
258 return js_NewNumberInRootedValue(cx, z, vp);
261 static JSBool
262 math_exp(JSContext *cx, uintN argc, jsval *vp)
264 jsdouble x, z;
266 if (argc == 0) {
267 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
268 return JS_TRUE;
270 x = js_ValueToNumber(cx, &vp[2]);
271 if (JSVAL_IS_NULL(vp[2]))
272 return JS_FALSE;
273 #ifdef _WIN32
274 if (!JSDOUBLE_IS_NaN(x)) {
275 if (x == *cx->runtime->jsPositiveInfinity) {
276 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
277 return JS_TRUE;
279 if (x == *cx->runtime->jsNegativeInfinity) {
280 *vp = JSVAL_ZERO;
281 return JS_TRUE;
284 #endif
285 z = exp(x);
286 return js_NewNumberInRootedValue(cx, z, vp);
289 static JSBool
290 math_floor(JSContext *cx, uintN argc, jsval *vp)
292 jsdouble x, z;
294 if (argc == 0) {
295 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
296 return JS_TRUE;
298 x = js_ValueToNumber(cx, &vp[2]);
299 if (JSVAL_IS_NULL(vp[2]))
300 return JS_FALSE;
301 z = floor(x);
302 return js_NewNumberInRootedValue(cx, z, vp);
305 static JSBool
306 math_log(JSContext *cx, uintN argc, jsval *vp)
308 jsdouble x, z;
310 if (argc == 0) {
311 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
312 return JS_TRUE;
314 x = js_ValueToNumber(cx, &vp[2]);
315 if (JSVAL_IS_NULL(vp[2]))
316 return JS_FALSE;
317 #if defined(SOLARIS) && defined(__GNUC__)
318 if (x < 0) {
319 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
320 return JS_TRUE;
322 #endif
323 z = log(x);
324 return js_NewNumberInRootedValue(cx, z, vp);
327 static JSBool
328 math_max(JSContext *cx, uintN argc, jsval *vp)
330 jsdouble x, z = *cx->runtime->jsNegativeInfinity;
331 jsval *argv;
332 uintN i;
334 if (argc == 0) {
335 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity);
336 return JS_TRUE;
338 argv = vp + 2;
339 for (i = 0; i < argc; i++) {
340 x = js_ValueToNumber(cx, &argv[i]);
341 if (JSVAL_IS_NULL(argv[i]))
342 return JS_FALSE;
343 if (JSDOUBLE_IS_NaN(x)) {
344 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
345 return JS_TRUE;
347 if (x == 0 && x == z && js_copysign(1.0, z) == -1)
348 z = x;
349 else
351 * Note: it is essential that you write the ternary expression
352 * here such that the false branch produces z not x, as the case
353 * of x=-0, z=0, for which we wind up in this expression but
354 * evaluate either > order as false, whether we do x>z *or* z>x.
356 z = (x > z) ? x : z;
358 return js_NewNumberInRootedValue(cx, z, vp);
361 static JSBool
362 math_min(JSContext *cx, uintN argc, jsval *vp)
364 jsdouble x, z = *cx->runtime->jsPositiveInfinity;
365 jsval *argv;
366 uintN i;
368 if (argc == 0) {
369 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
370 return JS_TRUE;
372 argv = vp + 2;
373 for (i = 0; i < argc; i++) {
374 x = js_ValueToNumber(cx, &argv[i]);
375 if (JSVAL_IS_NULL(argv[i]))
376 return JS_FALSE;
377 if (JSDOUBLE_IS_NaN(x)) {
378 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
379 return JS_TRUE;
381 if (x == 0 && x == z && js_copysign(1.0,x) == -1)
382 z = x;
383 else
384 z = (x < z) ? x : z;
386 return js_NewNumberInRootedValue(cx, z, vp);
389 static JSBool
390 math_pow(JSContext *cx, uintN argc, jsval *vp)
392 jsdouble x, y, z;
394 if (argc <= 1) {
395 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
396 return JS_TRUE;
398 x = js_ValueToNumber(cx, &vp[2]);
399 if (JSVAL_IS_NULL(vp[2]))
400 return JS_FALSE;
401 y = js_ValueToNumber(cx, &vp[3]);
402 if (JSVAL_IS_NULL(vp[3]))
403 return JS_FALSE;
405 * Because C99 and ECMA specify different behavior for pow(),
406 * we need to wrap the libm call to make it ECMA compliant.
408 if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) {
409 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
410 return JS_TRUE;
412 /* pow(x, +-0) is always 1, even for x = NaN. */
413 if (y == 0) {
414 *vp = JSVAL_ONE;
415 return JS_TRUE;
417 z = pow(x, y);
418 return js_NewNumberInRootedValue(cx, z, vp);
422 * Math.random() support, lifted from java.util.Random.java.
424 static void
425 random_setSeed(JSRuntime *rt, int64 seed)
427 int64 tmp;
429 JSLL_I2L(tmp, 1000);
430 JSLL_DIV(seed, seed, tmp);
431 JSLL_XOR(tmp, seed, rt->rngMultiplier);
432 JSLL_AND(rt->rngSeed, tmp, rt->rngMask);
435 void
436 js_random_init(JSRuntime *rt)
438 int64 tmp, tmp2;
440 /* Do at most once. */
441 if (rt->rngInitialized)
442 return;
443 rt->rngInitialized = JS_TRUE;
445 /* rt->rngMultiplier = 0x5DEECE66DL */
446 JSLL_ISHL(tmp, 0x5, 32);
447 JSLL_UI2L(tmp2, 0xDEECE66DL);
448 JSLL_OR(rt->rngMultiplier, tmp, tmp2);
450 /* rt->rngAddend = 0xBL */
451 JSLL_I2L(rt->rngAddend, 0xBL);
453 /* rt->rngMask = (1L << 48) - 1 */
454 JSLL_I2L(tmp, 1);
455 JSLL_SHL(tmp2, tmp, 48);
456 JSLL_SUB(rt->rngMask, tmp2, tmp);
458 /* rt->rngDscale = (jsdouble)(1L << 53) */
459 JSLL_SHL(tmp2, tmp, 53);
460 JSLL_L2D(rt->rngDscale, tmp2);
462 /* Finally, set the seed from current time. */
463 random_setSeed(rt, PRMJ_Now());
466 static uint32
467 random_next(JSRuntime *rt, int bits)
469 int64 nextseed, tmp;
470 uint32 retval;
472 JSLL_MUL(nextseed, rt->rngSeed, rt->rngMultiplier);
473 JSLL_ADD(nextseed, nextseed, rt->rngAddend);
474 JSLL_AND(nextseed, nextseed, rt->rngMask);
475 rt->rngSeed = nextseed;
476 JSLL_USHR(tmp, nextseed, 48 - bits);
477 JSLL_L2I(retval, tmp);
478 return retval;
481 jsdouble
482 js_random_nextDouble(JSRuntime *rt)
484 int64 tmp, tmp2;
485 jsdouble d;
487 JSLL_ISHL(tmp, random_next(rt, 26), 27);
488 JSLL_UI2L(tmp2, random_next(rt, 27));
489 JSLL_ADD(tmp, tmp, tmp2);
490 JSLL_L2D(d, tmp);
491 return d / rt->rngDscale;
494 static JSBool
495 math_random(JSContext *cx, uintN argc, jsval *vp)
497 JSRuntime *rt;
498 jsdouble z;
500 rt = cx->runtime;
501 JS_LOCK_RUNTIME(rt);
502 js_random_init(rt);
503 z = js_random_nextDouble(rt);
504 JS_UNLOCK_RUNTIME(rt);
505 return js_NewNumberInRootedValue(cx, z, vp);
508 #if defined _WIN32 && !defined WINCE && _MSC_VER < 1400
509 /* Try to work around apparent _copysign bustage in VC6 and VC7. */
510 double
511 js_copysign(double x, double y)
513 jsdpun xu, yu;
515 xu.d = x;
516 yu.d = y;
517 xu.s.hi &= ~JSDOUBLE_HI32_SIGNBIT;
518 xu.s.hi |= yu.s.hi & JSDOUBLE_HI32_SIGNBIT;
519 return xu.d;
521 #endif
523 static JSBool
524 math_round(JSContext *cx, uintN argc, jsval *vp)
526 jsdouble x, z;
528 if (argc == 0) {
529 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
530 return JS_TRUE;
532 x = js_ValueToNumber(cx, &vp[2]);
533 if (JSVAL_IS_NULL(vp[2]))
534 return JS_FALSE;
535 z = js_copysign(floor(x + 0.5), x);
536 return js_NewNumberInRootedValue(cx, z, vp);
539 static JSBool
540 math_sin(JSContext *cx, uintN argc, jsval *vp)
542 jsdouble x, z;
544 if (argc == 0) {
545 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
546 return JS_TRUE;
548 x = js_ValueToNumber(cx, &vp[2]);
549 if (JSVAL_IS_NULL(vp[2]))
550 return JS_FALSE;
551 z = sin(x);
552 return js_NewNumberInRootedValue(cx, z, vp);
555 static JSBool
556 math_sqrt(JSContext *cx, uintN argc, jsval *vp)
558 jsdouble x, z;
560 if (argc == 0) {
561 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
562 return JS_TRUE;
564 x = js_ValueToNumber(cx, &vp[2]);
565 if (JSVAL_IS_NULL(vp[2]))
566 return JS_FALSE;
567 z = sqrt(x);
568 return js_NewNumberInRootedValue(cx, z, vp);
571 static JSBool
572 math_tan(JSContext *cx, uintN argc, jsval *vp)
574 jsdouble x, z;
576 if (argc == 0) {
577 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
578 return JS_TRUE;
580 x = js_ValueToNumber(cx, &vp[2]);
581 if (JSVAL_IS_NULL(vp[2]))
582 return JS_FALSE;
583 z = tan(x);
584 return js_NewNumberInRootedValue(cx, z, vp);
587 #if JS_HAS_TOSOURCE
588 static JSBool
589 math_toSource(JSContext *cx, uintN argc, jsval *vp)
591 *vp = ATOM_KEY(CLASS_ATOM(cx, Math));
592 return JS_TRUE;
594 #endif
596 #ifdef JS_TRACER
598 #define MATH_BUILTIN_1(name) \
599 jsdouble FASTCALL js_Math_##name(jsdouble d) { return name(d); } \
600 JS_DEFINE_CALLINFO_1(DOUBLE, Math_##name, DOUBLE, 1, 1) \
601 static const JSTraceableNative math_##name##_trcinfo = \
602 { math_##name, &ci_Math_##name, "", "d", INFALLIBLE };
604 MATH_BUILTIN_1(sin)
605 MATH_BUILTIN_1(cos)
606 MATH_BUILTIN_1(sqrt)
607 MATH_BUILTIN_1(floor)
608 MATH_BUILTIN_1(ceil)
610 jsdouble FASTCALL
611 js_Math_log(jsdouble d)
613 #if defined(SOLARIS) && defined(__GNUC__)
614 if (d < 0)
615 return js_NaN;
616 #endif
617 return log(d);
620 jsdouble FASTCALL
621 js_Math_max(jsdouble d, jsdouble p)
623 if (JSDOUBLE_IS_NaN(d) || JSDOUBLE_IS_NaN(p))
624 return js_NaN;
626 if (p == 0 && p == d && js_copysign(1.0, d) == -1)
627 return p;
628 return (d > p) ? d : p;
631 jsdouble FASTCALL
632 js_Math_pow(jsdouble d, jsdouble p)
634 if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
635 return js_NaN;
636 if (p == 0)
637 return 1.0;
638 return pow(d, p);
641 jsdouble FASTCALL
642 js_Math_random(JSRuntime* rt)
644 JS_LOCK_RUNTIME(rt);
645 js_random_init(rt);
646 jsdouble z = js_random_nextDouble(rt);
647 JS_UNLOCK_RUNTIME(rt);
648 return z;
651 JS_DEFINE_CALLINFO_1(DOUBLE, Math_log, DOUBLE, 1, 1)
652 JS_DEFINE_CALLINFO_2(DOUBLE, Math_max, DOUBLE, DOUBLE, 1, 1)
653 JS_DEFINE_CALLINFO_2(DOUBLE, Math_pow, DOUBLE, DOUBLE, 1, 1)
654 JS_DEFINE_CALLINFO_1(DOUBLE, Math_random, RUNTIME, 0, 0)
656 static const JSTraceableNative math_log_trcinfo =
657 { math_log, &ci_Math_log, "", "d", INFALLIBLE };
658 static const JSTraceableNative math_max_trcinfo =
659 { math_max, &ci_Math_max, "", "dd", INFALLIBLE };
660 static const JSTraceableNative math_pow_trcinfo =
661 { math_pow, &ci_Math_pow, "", "dd", INFALLIBLE };
662 static const JSTraceableNative math_random_trcinfo =
663 { math_random, &ci_Math_random, "R", "", INFALLIBLE };
665 #endif /* JS_TRACER */
667 static JSFunctionSpec math_static_methods[] = {
668 #if JS_HAS_TOSOURCE
669 JS_FN(js_toSource_str, math_toSource, 0, 0),
670 #endif
671 JS_FN("abs", math_abs, 1, 0),
672 JS_FN("acos", math_acos, 1, 0),
673 JS_FN("asin", math_asin, 1, 0),
674 JS_FN("atan", math_atan, 1, 0),
675 JS_FN("atan2", math_atan2, 2, 0),
676 JS_TN("ceil", math_ceil, 1, 0, &math_ceil_trcinfo),
677 JS_TN("cos", math_cos, 1, 0, &math_cos_trcinfo),
678 JS_FN("exp", math_exp, 1, 0),
679 JS_TN("floor", math_floor, 1, 0, &math_floor_trcinfo),
680 JS_TN("log", math_log, 1, 0, &math_log_trcinfo),
681 JS_TN("max", math_max, 2, 0, &math_max_trcinfo),
682 JS_FN("min", math_min, 2, 0),
683 JS_TN("pow", math_pow, 2, 0, &math_pow_trcinfo),
684 JS_TN("random", math_random, 0, 0, &math_random_trcinfo),
685 JS_FN("round", math_round, 1, 0),
686 JS_TN("sin", math_sin, 1, 0, &math_sin_trcinfo),
687 JS_TN("sqrt", math_sqrt, 1, 0, &math_sqrt_trcinfo),
688 JS_FN("tan", math_tan, 1, 0),
689 JS_FS_END
692 JSObject *
693 js_InitMathClass(JSContext *cx, JSObject *obj)
695 JSObject *Math;
697 Math = JS_NewObject(cx, &js_MathClass, NULL, obj);
698 if (!Math)
699 return NULL;
700 if (!JS_DefineProperty(cx, obj, js_Math_str, OBJECT_TO_JSVAL(Math),
701 JS_PropertyStub, JS_PropertyStub,
702 JSPROP_READONLY | JSPROP_PERMANENT))
703 return NULL;
705 if (!JS_DefineFunctions(cx, Math, math_static_methods))
706 return NULL;
707 if (!JS_DefineConstDoubles(cx, Math, math_constants))
708 return NULL;
709 return Math;