Skip to content

Commit 12838ac

Browse files
authored
fix: Proper parseFloat for signed zeros inputs (#2483)
1 parent 8ae597d commit 12838ac

File tree

4 files changed

+378
-316
lines changed

4 files changed

+378
-316
lines changed

std/assembly/util/string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ export function strtod(str: string): f64 {
825825
code = <u32>load<u16>(ptr += 2);
826826
--len;
827827
}
828-
if (len <= 0) return 0;
828+
if (len <= 0) return 0.0 * sign;
829829
const capacity = 19; // int(64 * 0.3010)
830830
var pointed = false;
831831
var consumed = 0;
@@ -836,7 +836,7 @@ export function strtod(str: string): f64 {
836836
ptr += 2; --len;
837837
if (!len && noDigits) return NaN;
838838
for (pointed = true; (code = <u32>load<u16>(ptr)) == CharCode._0; --position, ptr += 2) --len;
839-
if (len <= 0) return 0;
839+
if (len <= 0) return 0.0 * sign;
840840
if (!position && noDigits && code - CharCode._0 >= 10) return NaN;
841841
}
842842
for (let digit = code - CharCode._0; digit < 10 || (code == CharCode.DOT && !pointed); digit = code - CharCode._0) {

0 commit comments

Comments
 (0)