diff --git a/bend2/comp.ts b/bend2/comp.ts index 64dbc33669..2433237ca3 100644 --- a/bend2/comp.ts +++ b/bend2/comp.ts @@ -6045,8 +6045,8 @@ function f32_from_bits(u) { function f32_read(s) { const re = /^[\t\n\v\f\r ]*[+-]?((\d+(?:\.\d*)?|\.\d+)(e[+-]?\d+)?|inf(inity)?|nan)$/i; - const v = f32_round(s.replace(/inf\w*/i, "Infinity")); - return re.test(s) ? {$: "Some", value: v} : {$: "None"}; + return re.test(s) ? {$: "Some", value: f32_round( + s.replace(/inf\w*/i, "Infinity"))} : {$: "None"}; } const f32_round = ${Bend.f32_round}; diff --git a/tests/run/f32_read_long_invalid.bend b/tests/run/f32_read_long_invalid.bend index 95e7dca347..080d3763d9 100644 --- a/tests/run/f32_read_long_invalid.bend +++ b/tests/run/f32_read_long_invalid.bend @@ -1,14 +1,15 @@ # The JS reader must reject a long integer with an invalid suffix without -# splitting its digits between two overlapping repetitions. Build it with -# a tail-recursive accumulator so string construction does not exhaust the stack. +# splitting its digits between two overlapping repetitions. A long decimal +# midpoint with a trailing space must be rejected before exact rounding. +# Build both with a tail-recursive accumulator to avoid exhausting the stack. import Base -def digits(n: Nat, acc: String) -> String: +def digits(n: Nat, +digit: Char, acc: String) -> String: match n: case 0n: acc case 1n+p: - digits(p, SCon{'1', acc}) + digits(p, digit, SCon{digit, acc}) def seen(m: Maybe<&2, F32>) -> String: match m: @@ -18,6 +19,10 @@ def seen(m: Maybe<&2, F32>) -> String: F32.show(v) def main() -> IO(Unit): - IO.print(seen(F32.read(digits(100000n, "x")))) + do IO: + IO.print(seen(F32.read(digits(100000n, '1', "x")))) + IO.print(seen(F32.read("1.000000059604644775390625" + ++ digits(5000n, '0', " ")))) #|none +#|none