Bug 463806 - [PATCH][@font-face] Downloaded font activation on Mac may fail due to...
[wine-gecko.git] / js / src / jsmath.cpp
blob3ae0efef546bc84bd0d80960290d3577ce266f6f
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 inline jsdouble JS_FASTCALL
183 math_atan2_kernel(jsdouble x, jsdouble y)
185 #if defined(_MSC_VER)
187 * MSVC's atan2 does not yield the result demanded by ECMA when both x
188 * and y are infinite.
189 * - The result is a multiple of pi/4.
190 * - The sign of x determines the sign of the result.
191 * - The sign of y determines the multiplicator, 1 or 3.
193 if (JSDOUBLE_IS_INFINITE(x) && JSDOUBLE_IS_INFINITE(y)) {
194 jsdouble z = js_copysign(M_PI / 4, x);
195 if (y < 0)
196 z *= 3;
197 return z;
199 #endif
201 #if defined(SOLARIS) && defined(__GNUC__)
202 if (x == 0) {
203 if (JSDOUBLE_IS_NEGZERO(y))
204 return js_copysign(M_PI, x);
205 if (y == 0)
206 return x;
208 #endif
209 return atan2(x, y);
212 static JSBool
213 math_atan2(JSContext *cx, uintN argc, jsval *vp)
215 jsdouble x, y;
217 if (argc <= 1) {
218 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
219 return JS_TRUE;
221 x = js_ValueToNumber(cx, &vp[2]);
222 if (JSVAL_IS_NULL(vp[2]))
223 return JS_FALSE;
224 y = js_ValueToNumber(cx, &vp[3]);
225 if (JSVAL_IS_NULL(vp[3]))
226 return JS_FALSE;
227 return js_NewNumberInRootedValue(cx, math_atan2_kernel (x, y), vp);
230 static JSBool
231 math_ceil(JSContext *cx, uintN argc, jsval *vp)
233 jsdouble x, z;
235 if (argc == 0) {
236 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
237 return JS_TRUE;
239 x = js_ValueToNumber(cx, &vp[2]);
240 if (JSVAL_IS_NULL(vp[2]))
241 return JS_FALSE;
242 z = ceil(x);
243 return js_NewNumberInRootedValue(cx, z, vp);
246 static JSBool
247 math_cos(JSContext *cx, uintN argc, jsval *vp)
249 jsdouble x, z;
251 if (argc == 0) {
252 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
253 return JS_TRUE;
255 x = js_ValueToNumber(cx, &vp[2]);
256 if (JSVAL_IS_NULL(vp[2]))
257 return JS_FALSE;
258 z = cos(x);
259 return js_NewNumberInRootedValue(cx, z, vp);
262 static JSBool
263 math_exp(JSContext *cx, uintN argc, jsval *vp)
265 jsdouble x, z;
267 if (argc == 0) {
268 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
269 return JS_TRUE;
271 x = js_ValueToNumber(cx, &vp[2]);
272 if (JSVAL_IS_NULL(vp[2]))
273 return JS_FALSE;
274 #ifdef _WIN32
275 if (!JSDOUBLE_IS_NaN(x)) {
276 if (x == *cx->runtime->jsPositiveInfinity) {
277 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
278 return JS_TRUE;
280 if (x == *cx->runtime->jsNegativeInfinity) {
281 *vp = JSVAL_ZERO;
282 return JS_TRUE;
285 #endif
286 z = exp(x);
287 return js_NewNumberInRootedValue(cx, z, vp);
290 static JSBool
291 math_floor(JSContext *cx, uintN argc, jsval *vp)
293 jsdouble x, z;
295 if (argc == 0) {
296 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
297 return JS_TRUE;
299 x = js_ValueToNumber(cx, &vp[2]);
300 if (JSVAL_IS_NULL(vp[2]))
301 return JS_FALSE;
302 z = floor(x);
303 return js_NewNumberInRootedValue(cx, z, vp);
306 static JSBool
307 math_log(JSContext *cx, uintN argc, jsval *vp)
309 jsdouble x, z;
311 if (argc == 0) {
312 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
313 return JS_TRUE;
315 x = js_ValueToNumber(cx, &vp[2]);
316 if (JSVAL_IS_NULL(vp[2]))
317 return JS_FALSE;
318 #if defined(SOLARIS) && defined(__GNUC__)
319 if (x < 0) {
320 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
321 return JS_TRUE;
323 #endif
324 z = log(x);
325 return js_NewNumberInRootedValue(cx, z, vp);
328 static JSBool
329 math_max(JSContext *cx, uintN argc, jsval *vp)
331 jsdouble x, z = *cx->runtime->jsNegativeInfinity;
332 jsval *argv;
333 uintN i;
335 if (argc == 0) {
336 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNegativeInfinity);
337 return JS_TRUE;
339 argv = vp + 2;
340 for (i = 0; i < argc; i++) {
341 x = js_ValueToNumber(cx, &argv[i]);
342 if (JSVAL_IS_NULL(argv[i]))
343 return JS_FALSE;
344 if (JSDOUBLE_IS_NaN(x)) {
345 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
346 return JS_TRUE;
348 if (x == 0 && x == z) {
349 if (js_copysign(1.0, z) == -1)
350 z = x;
351 } else {
352 z = (x > z) ? x : z;
355 return js_NewNumberInRootedValue(cx, z, vp);
358 static JSBool
359 math_min(JSContext *cx, uintN argc, jsval *vp)
361 jsdouble x, z = *cx->runtime->jsPositiveInfinity;
362 jsval *argv;
363 uintN i;
365 if (argc == 0) {
366 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsPositiveInfinity);
367 return JS_TRUE;
369 argv = vp + 2;
370 for (i = 0; i < argc; i++) {
371 x = js_ValueToNumber(cx, &argv[i]);
372 if (JSVAL_IS_NULL(argv[i]))
373 return JS_FALSE;
374 if (JSDOUBLE_IS_NaN(x)) {
375 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
376 return JS_TRUE;
378 if (x == 0 && x == z) {
379 if (js_copysign(1.0, x) == -1)
380 z = x;
381 } else {
382 z = (x < z) ? x : z;
385 return js_NewNumberInRootedValue(cx, z, vp);
388 static JSBool
389 math_pow(JSContext *cx, uintN argc, jsval *vp)
391 jsdouble x, y, z;
393 if (argc <= 1) {
394 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
395 return JS_TRUE;
397 x = js_ValueToNumber(cx, &vp[2]);
398 if (JSVAL_IS_NULL(vp[2]))
399 return JS_FALSE;
400 y = js_ValueToNumber(cx, &vp[3]);
401 if (JSVAL_IS_NULL(vp[3]))
402 return JS_FALSE;
404 * Because C99 and ECMA specify different behavior for pow(),
405 * we need to wrap the libm call to make it ECMA compliant.
407 if (!JSDOUBLE_IS_FINITE(y) && (x == 1.0 || x == -1.0)) {
408 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
409 return JS_TRUE;
411 /* pow(x, +-0) is always 1, even for x = NaN. */
412 if (y == 0) {
413 *vp = JSVAL_ONE;
414 return JS_TRUE;
416 z = pow(x, y);
417 return js_NewNumberInRootedValue(cx, z, vp);
421 * Math.random() support, lifted from java.util.Random.java.
423 static void
424 random_setSeed(JSRuntime *rt, int64 seed)
426 int64 tmp;
428 JSLL_I2L(tmp, 1000);
429 JSLL_DIV(seed, seed, tmp);
430 JSLL_XOR(tmp, seed, rt->rngMultiplier);
431 JSLL_AND(rt->rngSeed, tmp, rt->rngMask);
434 void
435 js_random_init(JSRuntime *rt)
437 int64 tmp, tmp2;
439 /* Do at most once. */
440 if (rt->rngInitialized)
441 return;
442 rt->rngInitialized = JS_TRUE;
444 /* rt->rngMultiplier = 0x5DEECE66DL */
445 JSLL_ISHL(tmp, 0x5, 32);
446 JSLL_UI2L(tmp2, 0xDEECE66DL);
447 JSLL_OR(rt->rngMultiplier, tmp, tmp2);
449 /* rt->rngAddend = 0xBL */
450 JSLL_I2L(rt->rngAddend, 0xBL);
452 /* rt->rngMask = (1L << 48) - 1 */
453 JSLL_I2L(tmp, 1);
454 JSLL_SHL(tmp2, tmp, 48);
455 JSLL_SUB(rt->rngMask, tmp2, tmp);
457 /* rt->rngDscale = (jsdouble)(1L << 53) */
458 JSLL_SHL(tmp2, tmp, 53);
459 JSLL_L2D(rt->rngDscale, tmp2);
461 /* Finally, set the seed from current time. */
462 random_setSeed(rt, PRMJ_Now());
465 static uint32
466 random_next(JSRuntime *rt, int bits)
468 int64 nextseed, tmp;
469 uint32 retval;
471 JSLL_MUL(nextseed, rt->rngSeed, rt->rngMultiplier);
472 JSLL_ADD(nextseed, nextseed, rt->rngAddend);
473 JSLL_AND(nextseed, nextseed, rt->rngMask);
474 rt->rngSeed = nextseed;
475 JSLL_USHR(tmp, nextseed, 48 - bits);
476 JSLL_L2I(retval, tmp);
477 return retval;
480 jsdouble
481 js_random_nextDouble(JSRuntime *rt)
483 int64 tmp, tmp2;
484 jsdouble d;
486 JSLL_ISHL(tmp, random_next(rt, 26), 27);
487 JSLL_UI2L(tmp2, random_next(rt, 27));
488 JSLL_ADD(tmp, tmp, tmp2);
489 JSLL_L2D(d, tmp);
490 return d / rt->rngDscale;
493 static JSBool
494 math_random(JSContext *cx, uintN argc, jsval *vp)
496 JSRuntime *rt;
497 jsdouble z;
499 rt = cx->runtime;
500 JS_LOCK_RUNTIME(rt);
501 js_random_init(rt);
502 z = js_random_nextDouble(rt);
503 JS_UNLOCK_RUNTIME(rt);
504 return js_NewNumberInRootedValue(cx, z, vp);
507 #if defined _WIN32 && !defined WINCE && _MSC_VER < 1400
508 /* Try to work around apparent _copysign bustage in VC6 and VC7. */
509 double
510 js_copysign(double x, double y)
512 jsdpun xu, yu;
514 xu.d = x;
515 yu.d = y;
516 xu.s.hi &= ~JSDOUBLE_HI32_SIGNBIT;
517 xu.s.hi |= yu.s.hi & JSDOUBLE_HI32_SIGNBIT;
518 return xu.d;
520 #endif
522 static JSBool
523 math_round(JSContext *cx, uintN argc, jsval *vp)
525 jsdouble x, z;
527 if (argc == 0) {
528 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
529 return JS_TRUE;
531 x = js_ValueToNumber(cx, &vp[2]);
532 if (JSVAL_IS_NULL(vp[2]))
533 return JS_FALSE;
534 z = js_copysign(floor(x + 0.5), x);
535 return js_NewNumberInRootedValue(cx, z, vp);
538 static JSBool
539 math_sin(JSContext *cx, uintN argc, jsval *vp)
541 jsdouble x, z;
543 if (argc == 0) {
544 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
545 return JS_TRUE;
547 x = js_ValueToNumber(cx, &vp[2]);
548 if (JSVAL_IS_NULL(vp[2]))
549 return JS_FALSE;
550 z = sin(x);
551 return js_NewNumberInRootedValue(cx, z, vp);
554 static JSBool
555 math_sqrt(JSContext *cx, uintN argc, jsval *vp)
557 jsdouble x, z;
559 if (argc == 0) {
560 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
561 return JS_TRUE;
563 x = js_ValueToNumber(cx, &vp[2]);
564 if (JSVAL_IS_NULL(vp[2]))
565 return JS_FALSE;
566 z = sqrt(x);
567 return js_NewNumberInRootedValue(cx, z, vp);
570 static JSBool
571 math_tan(JSContext *cx, uintN argc, jsval *vp)
573 jsdouble x, z;
575 if (argc == 0) {
576 *vp = DOUBLE_TO_JSVAL(cx->runtime->jsNaN);
577 return JS_TRUE;
579 x = js_ValueToNumber(cx, &vp[2]);
580 if (JSVAL_IS_NULL(vp[2]))
581 return JS_FALSE;
582 z = tan(x);
583 return js_NewNumberInRootedValue(cx, z, vp);
586 #if JS_HAS_TOSOURCE
587 static JSBool
588 math_toSource(JSContext *cx, uintN argc, jsval *vp)
590 *vp = ATOM_KEY(CLASS_ATOM(cx, Math));
591 return JS_TRUE;
593 #endif
595 #ifdef JS_TRACER
597 #define MATH_BUILTIN_1(name) \
598 static jsdouble FASTCALL math_##name##_tn(jsdouble d) { return name(d); } \
599 JS_DEFINE_TRCINFO_1(math_##name, \
600 (1, (static, DOUBLE, math_##name##_tn, DOUBLE, 1, 1)))
602 MATH_BUILTIN_1(sin)
603 MATH_BUILTIN_1(cos)
604 MATH_BUILTIN_1(sqrt)
605 MATH_BUILTIN_1(floor)
606 MATH_BUILTIN_1(ceil)
608 static jsdouble FASTCALL
609 math_abs_tn(jsdouble d)
611 return fabs(d);
614 static jsdouble FASTCALL
615 math_log_tn(jsdouble d)
617 #if defined(SOLARIS) && defined(__GNUC__)
618 if (d < 0)
619 return js_NaN;
620 #endif
621 return log(d);
624 static jsdouble FASTCALL
625 math_max_tn(jsdouble d, jsdouble p)
627 if (JSDOUBLE_IS_NaN(d) || JSDOUBLE_IS_NaN(p))
628 return js_NaN;
630 if (p == 0 && p == d) {
631 if (js_copysign(1.0, d) == -1)
632 return p;
633 return d;
635 return (p > d) ? p : d;
638 static jsdouble FASTCALL
639 math_pow_tn(jsdouble d, jsdouble p)
641 if (!JSDOUBLE_IS_FINITE(p) && (d == 1.0 || d == -1.0))
642 return js_NaN;
643 if (p == 0)
644 return 1.0;
645 return pow(d, p);
648 static jsdouble FASTCALL
649 math_random_tn(JSRuntime* rt)
651 JS_LOCK_RUNTIME(rt);
652 js_random_init(rt);
653 jsdouble z = js_random_nextDouble(rt);
654 JS_UNLOCK_RUNTIME(rt);
655 return z;
658 static jsdouble FASTCALL
659 math_round_tn(jsdouble x)
661 return js_copysign(floor(x + 0.5), x);
664 JS_DEFINE_TRCINFO_1(math_abs,
665 (1, (static, DOUBLE, math_abs_tn, DOUBLE, 1, 1)))
666 JS_DEFINE_TRCINFO_1(math_log,
667 (1, (static, DOUBLE, math_log_tn, DOUBLE, 1, 1)))
668 JS_DEFINE_TRCINFO_1(math_max,
669 (2, (static, DOUBLE, math_max_tn, DOUBLE, DOUBLE, 1, 1)))
670 JS_DEFINE_TRCINFO_1(math_pow,
671 (2, (static, DOUBLE, math_pow_tn, DOUBLE, DOUBLE, 1, 1)))
672 JS_DEFINE_TRCINFO_1(math_random,
673 (1, (static, DOUBLE, math_random_tn, RUNTIME, 0, 0)))
674 JS_DEFINE_TRCINFO_1(math_round,
675 (1, (static, DOUBLE, math_round_tn, DOUBLE, 1, 1)))
677 #endif /* JS_TRACER */
679 static JSFunctionSpec math_static_methods[] = {
680 #if JS_HAS_TOSOURCE
681 JS_FN(js_toSource_str, math_toSource, 0, 0),
682 #endif
683 JS_TN("abs", math_abs, 1, 0, math_abs_trcinfo),
684 JS_FN("acos", math_acos, 1, 0),
685 JS_FN("asin", math_asin, 1, 0),
686 JS_FN("atan", math_atan, 1, 0),
687 JS_FN("atan2", math_atan2, 2, 0),
688 JS_TN("ceil", math_ceil, 1, 0, math_ceil_trcinfo),
689 JS_TN("cos", math_cos, 1, 0, math_cos_trcinfo),
690 JS_FN("exp", math_exp, 1, 0),
691 JS_TN("floor", math_floor, 1, 0, math_floor_trcinfo),
692 JS_TN("log", math_log, 1, 0, math_log_trcinfo),
693 JS_TN("max", math_max, 2, 0, math_max_trcinfo),
694 JS_FN("min", math_min, 2, 0),
695 JS_TN("pow", math_pow, 2, 0, math_pow_trcinfo),
696 JS_TN("random", math_random, 0, 0, math_random_trcinfo),
697 JS_TN("round", math_round, 1, 0, math_round_trcinfo),
698 JS_TN("sin", math_sin, 1, 0, math_sin_trcinfo),
699 JS_TN("sqrt", math_sqrt, 1, 0, math_sqrt_trcinfo),
700 JS_FN("tan", math_tan, 1, 0),
701 JS_FS_END
704 JSObject *
705 js_InitMathClass(JSContext *cx, JSObject *obj)
707 JSObject *Math;
709 Math = JS_NewObject(cx, &js_MathClass, NULL, obj);
710 if (!Math)
711 return NULL;
712 if (!JS_DefineProperty(cx, obj, js_Math_str, OBJECT_TO_JSVAL(Math),
713 JS_PropertyStub, JS_PropertyStub, 0)) {
714 return NULL;
717 if (!JS_DefineFunctions(cx, Math, math_static_methods))
718 return NULL;
719 if (!JS_DefineConstDoubles(cx, Math, math_constants))
720 return NULL;
721 return Math;