Commit Graph

19 Commits

Author SHA1 Message Date
Tor Andersson
3bd234c685 Math.random: Use Lehmer LCG instead of borrowing the hack from musl.
For simplicity of implementation, use the minimal standard generator
described in "Random Number Generators: Good ones are hard to find"
by Park & Miller (ACM 1988, Volume 31, Number 10).
2021-11-05 12:59:02 +01:00
Tor Andersson
d3feec4365 Issue #85: Use explicit seed in Math.random(). 2019-02-25 12:15:56 +01:00
Tor Andersson
81d5b30acc Initialize random seed for Math.random(). 2018-10-26 14:57:56 +02:00
Tor Andersson
336097c57f Reimplement Math.round using floor(). 2017-01-24 14:48:14 +01:00
Tor Andersson
a2fcfd69fe Define built-in functions with the full name.
Improves error messages and stack traces.
2016-04-28 12:57:22 +02:00
Tor Andersson
3e3c382a0c Avoid using 'unsigned int'.
Mixing signed and unsigned ints is just a plain headache.
2016-04-27 16:26:00 +02:00
Tor Andersson
c90c32326e Fix bugs introduced when moving from argc to js_gettop.
The 'length' field of a function is used to fill in missing arguments
with undefined; this does not mesh well with functions that query for
missing arguments using js_gettop. Set their lengths to 0 instead.
2016-04-15 12:18:34 +02:00
Tor Andersson
4a7ffbf2ed Fix bug in Math.random().
Return value should be 0 <= x < 1. Fix typo and divide by RAND_MAX + 1.0
to avoid integer overflow.
2014-11-10 12:19:22 +01:00
Szabolcs Nagy
85d4c8a52c Fix Math.min and Math.max to accept zero args and handle -0
In case of no arguments +-Infinity should be returned. -0 is
smaller than +0 and any NaN input should turn the result into NaN.
(because of the NaN semantics libc fmin, fmax cannot be used: they
return the other argument if one is NaN)
2014-10-17 13:55:47 +02:00
Szabolcs Nagy
a88e9d4c5e Fix Math.atan2 and Math.pow argument evaluation order
Math.pow has subtly different semantics than ISO C pow for the
non-finite powers of +-1, so that's handled separately.
(ECMA requires NAN result, in ISO C Annex F pow(1,any) == 1 and
pow(-1,+-inf) == 1)
2014-10-17 13:55:47 +02:00
Szabolcs Nagy
e107fcf8ca Fix Math.abs to use fabs instead of int abs 2014-10-17 13:55:47 +02:00
Tor Andersson
43de5a093f Implement Math.round according to the (stupid) specification.
Thanks to nsz for pointing out this implementation.
2014-10-15 13:12:45 +02:00
Tor Andersson
d366e4b852 Don't pass argc to functions. Use js_gettop instead. 2014-03-12 16:40:48 +01:00
Tor Andersson
70b0d8b902 Change C functions to not have a return value.
They should always push a return value on the JS stack.
2014-02-25 00:56:33 +01:00
Tor Andersson
c7e9ab0b05 Fix signed/unsigned comparison warnings. 2014-02-24 23:55:58 +01:00
Tor Andersson
588fdd18d6 Small cleanups. 2014-02-18 14:38:50 +01:00
Tor Andersson
195816c208 Set property attributes on built-in objects and respect DontEnum. 2014-01-23 17:53:22 +01:00
Tor Andersson
ca79fc1497 jsmath.c expanded 2014-01-21 14:14:51 +01:00
Tor Andersson
3a92e13e47 Rename files and move a few functions around. 2014-01-21 13:58:32 +01:00