diff options
author | Parashurama <Rhagdamaziel@ymail.com> | 2016-05-18 12:12:01 +0200 |
---|---|---|
committer | Parashurama <Rhagdamaziel@ymail.com> | 2016-05-18 12:12:01 +0200 |
commit | f5761e23d3a6424eab3979d66e6605b1611b1d0c (patch) | |
tree | b137a5eef09003e594814ddd8f4d9304f979c97a | |
parent | 3f075b7921a32417857e765c13323a65c60b5e01 (diff) | |
download | Nim-f5761e23d3a6424eab3979d66e6605b1611b1d0c.tar.gz |
fix issue 4181. add testcase.
-rw-r--r-- | lib/system/sysstr.nim | 7 | ||||
-rw-r--r-- | tests/float/tfloat5.nim | 15 |
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index b1a3bee55..3177d05bd 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -329,9 +329,11 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, frac_exponent= 0 exp_sign = 1 first_digit = 0 + has_sign = false # Sign? if s[i] == '+' or s[i] == '-': + has_sign = true if s[i] == '-': sign = -1.0 inc(i) @@ -387,8 +389,9 @@ proc nimParseBiggestFloat(s: string, number: var BiggestFloat, while s[i] == '_': inc(i) # if has no digits: return error - # test for special case 0.0'f - if kdigits + fdigits <= 0 and i == start: + if kdigits + fdigits <= 0 and + (i == start or # was only zero + has_sign) : # or only '+' or '- return 0 if s[i] in {'e', 'E'}: diff --git a/tests/float/tfloat5.nim b/tests/float/tfloat5.nim new file mode 100644 index 000000000..aa7dc6c53 --- /dev/null +++ b/tests/float/tfloat5.nim @@ -0,0 +1,15 @@ +discard """ + file: "tfloat5.nim" + output: '''0 : 0.0 +0 : 0.0 +0 : 0.0 +0 : 0.0''' +""" + +import parseutils + +var f: float +echo "*".parseFloat(f), " : ", f +echo "/".parseFloat(f), " : ", f +echo "+".parseFloat(f), " : ", f +echo "-".parseFloat(f), " : ", f |