mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
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)
This commit is contained in:
parent
2ff03ecfa8
commit
c5c9494f48
Notes:
sideshowbarker
2024-07-18 18:19:43 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/c5c9494f488 Pull-request: https://github.com/SerenityOS/serenity/pull/7036
2 changed files with 3 additions and 2 deletions
|
@ -80,7 +80,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
|
|||
if (negative)
|
||||
number *= -1;
|
||||
|
||||
u32 int_part = floor(number);
|
||||
u64 int_part = floor(number);
|
||||
double decimal_part = number - int_part;
|
||||
|
||||
Vector<char> backwards_characters;
|
||||
|
@ -111,7 +111,7 @@ JS_DEFINE_NATIVE_FUNCTION(NumberPrototype::to_string)
|
|||
|
||||
for (u8 i = 0; i < precision; ++i) {
|
||||
decimal_part *= radix;
|
||||
u32 integral = floor(decimal_part);
|
||||
u64 integral = floor(decimal_part);
|
||||
characters.append(digits[integral]);
|
||||
decimal_part -= integral;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ describe("correct behavior", () => {
|
|||
// Numbers above 2 ** 31 - 1 (Issue #3931)
|
||||
[2147483648, "2147483648"], // 2 ** 31
|
||||
[4294967295, "4294967295"], // 2 ** 32 - 1
|
||||
[18014398509481984, "18014398509481984"], // 2 ** 54
|
||||
].forEach(testCase => {
|
||||
expect(testCase[0].toString()).toBe(testCase[1]);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue