summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-05-17 06:21:34 +0800
committerGitHub <noreply@github.com>2023-05-17 00:21:34 +0200
commitf22e5067c5e0f375cb2263ec779d6e6ede108155 (patch)
treee08e1480574a8b603b88d2ba8c7933c5beeb7c5b
parenteecf12c4b5fa8a011b1fc1991b554a31ca9a4a27 (diff)
downloadNim-f22e5067c5e0f375cb2263ec779d6e6ede108155.tar.gz
fixes #21847; let `parseFloat` behave like `strtod` (#21854)
-rw-r--r--lib/system/strmantle.nim4
-rw-r--r--tests/float/tfloat4.nim10
2 files changed, 11 insertions, 3 deletions
diff --git a/lib/system/strmantle.nim b/lib/system/strmantle.nim
index ab158d6b7..60c63501c 100644
--- a/lib/system/strmantle.nim
+++ b/lib/system/strmantle.nim
@@ -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
diff --git a/tests/float/tfloat4.nim b/tests/float/tfloat4.nim
index f6216c374..2bb61eb58 100644
--- a/tests/float/tfloat4.nim
+++ b/tests/float/tfloat4.nim
@@ -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.")