Skip to content

Commit

Permalink
fixes #21847; let parseFloat behave like strtod (#21854)
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed May 16, 2023
1 parent eecf12c commit f22e506
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/system/strmantle.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ proc nimParseBiggestFloat(s: openArray[char], number: var BiggestFloat,

# if exponent greater than can be represented: +/- zero or infinity
if absExponent > 999:
if expNegative:
if integer == 0:
number = 0.0
elif expNegative:
number = 0.0*sign
else:
number = Inf*sign
Expand Down
10 changes: 8 additions & 2 deletions tests/float/tfloat4.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,14 @@ doAssert 0.9999999999999999 == ".9999999999999999".parseFloat

# bug #18400
var s = [-13.888888'f32]
assert $s[0] == "-13.888888"
doAssert $s[0] == "-13.888888"
var x = 1.23456789012345'f32
assert $x == "1.2345679"
doAssert $x == "1.2345679"

# bug #21847
doAssert parseFloat"0e+42" == 0.0
doAssert parseFloat"0e+42949672969" == 0.0
doAssert parseFloat"0e+42949672970" == 0.0
doAssert parseFloat"0e+42949623223346323563272970" == 0.0

echo("passed all tests.")

0 comments on commit f22e506

Please sign in to comment.