Commit graph

17 commits

Author SHA1 Message Date
Ben Abraham
a9c9c8c076 LibJS: Fix rounding issues in Number.toFixed
toFixed was not rounding properly when trimming a number.
ie: (0.00006).toFixed(4) should be "0.00001" but was returning "0.0000"
2022-03-02 08:34:04 +01:00
Linus Groh
140f1d9e55 LibJS/Tests: Enable Number.isInteger() test that now passes 2022-01-24 20:39:01 +00:00
Timothy Flynn
534b2be16f LibJS: Implement Number.prototype.toExponential 2022-01-04 13:07:42 +00:00
Timothy Flynn
dc984c53d8 LibJS: Implement Number.prototype.toPrecision
As noted in the prototype comments, this implementation becomes less
accurate as the precision approaches the limit of 100. For example:

    (3).toPrecision(100)

Should result in "3." followed by 99 "0"s. However, due to the loss of
accuracy in the floating point computations, we currently result in
"2.9999999...".
2022-01-04 13:07:42 +00:00
Luke Wilde
2d26a50d28 LibJS: Fix toFixed throwing on undefined, null and NaN fractionDigits
It was checking the original fractionDigits argument was a finite
number instead of the coerced fraction_digits.
2021-12-26 20:37:44 +01:00
Timothy Flynn
c19c3205ff LibJS: Implement ECMA-402 Number.prototype.toLocaleString 2021-11-17 09:01:32 +00:00
Timothy Flynn
76589d6728 LibJS: Change wording of ErrorType::NotA to be independent of context
Currently, we have NotA and NotAn, to be used dependent on whether the
following word begins with a vowel or not. To avoid this, change the
wording on NotA to be independent of this context.
2021-09-12 00:16:39 +02:00
Linus Groh
a8ba2f4b21 LibJS/Tests: Fix bad copy and paste that crept into a lot of tests
The top-level function should have been `describe()``, but instead it's
been nested `test()`s.
2021-08-07 12:10:34 +01:00
Linus Groh
54e1180f61 LibJS: Uncomment Number.isInteger() tests that now pass :^) 2021-07-11 22:03:04 +01:00
Idan Horowitz
c31392510a LibJS: Add the Number.prototype.toFixed method 2021-06-19 16:13:59 +01:00
Linus Groh
8e26c7a1dd LibJS: Make Number() constructor spec compliant
By using to_numeric() and adding BigInt handling, we get support for
`Number(123n)`.

Fixes #8125.
2021-06-19 01:34:17 +01:00
Luke
02de3cbce3 LibJS: Add Number.parseInt
This is initialized to be the same function object as the initial value
of the parseInt function on the global object.
2021-06-18 10:29:33 +01:00
Linus Groh
d255e6892b LibJS: Update NumberPrototype's this_number_value() to take a Value
This is now about as close to the spec as it gets - instead of querying
the |this| value inside of the function, we now pass it in from the
outside.
Also get rid of the oddly specific error messages, they're nice but
pretty inconsistent with most others. Let's prefer consistency and
simplicity for now.

Other than that, no functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
adc3de4480 LibJS: Implement Number.prototype.valueOf() 2021-06-06 06:56:08 +01:00
Luke
c5c9494f48 LibJS: Use u64 instead of u32 in NumberPrototype::to_string
Update to #7033
Partial fix for #7034 (just ups the range to about 2 ** 54 before
losing precision)
2021-05-11 18:29:55 +01:00
Luke
2ff03ecfa8 LibJS: Make number parts unsigned in NumberPrototype::to_string
Fixes #3931
2021-05-11 17:29:37 +01:00
Andreas Kling
13d7c09125 Libraries: Move to Userland/Libraries/ 2021-01-12 12:17:46 +01:00