Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bend2/comp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
15 changes: 10 additions & 5 deletions tests/run/f32_read_long_invalid.bend
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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<Unit>:
IO.print(seen(F32.read(digits(100000n, '1', "x"))))
IO.print(seen(F32.read("1.000000059604644775390625"
++ digits(5000n, '0', " "))))

#|none
#|none