diff options
-rw-r--r-- | lib/system/sysstr.nim | 7 | ||||
-rw-r--r-- | tests/float/tfloat4.nim | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index 4c5f3d9a1..514223af2 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -386,8 +386,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, kdigits, fdigits = 0 exponent: int integer: uint64 - fraction: uint64 - frac_exponent= 0 + frac_exponent = 0 exp_sign = 1 first_digit = -1 has_sign = false @@ -480,7 +479,8 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, # if integer is representable in 53 bits: fast path # max fast path integer is 1<<53 - 1 or 8999999999999999 (16 digits) - if kdigits + fdigits <= 16 and first_digit <= 8: + let digits = kdigits + fdigits + if digits <= 15 or (digits <= 16 and first_digit <= 8): # max float power of ten with set bits above the 53th bit is 10^22 if abs_exponent <= 22: if exp_negative: @@ -504,6 +504,7 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, result = i - start i = start # re-parse without error checking, any error should be handled by the code above. + if s[i] == '.': i.inc while s[i] in {'0'..'9','+','-'}: if ti < maxlen: t[ti] = s[i]; inc(ti) diff --git a/tests/float/tfloat4.nim b/tests/float/tfloat4.nim index 559c8aaca..68df56be8 100644 --- a/tests/float/tfloat4.nim +++ b/tests/float/tfloat4.nim @@ -48,5 +48,11 @@ doAssert "2.71828182845904523536028747".parseFloat == 2.71828182845904523536028747 doAssert 0.00097656250000000021684043449710088680149056017398834228515625 == "0.00097656250000000021684043449710088680149056017398834228515625".parseFloat +doAssert 0.00998333 == ".00998333".parseFloat +doAssert 0.00128333 == ".00128333".parseFloat +doAssert 999999999999999.0 == "999999999999999.0".parseFloat +doAssert 9999999999999999.0 == "9999999999999999.0".parseFloat +doAssert 0.999999999999999 == ".999999999999999".parseFloat +doAssert 0.9999999999999999 == ".9999999999999999".parseFloat echo("passed all tests.") |