From f5761e23d3a6424eab3979d66e6605b1611b1d0c Mon Sep 17 00:00:00 2001 From: Parashurama Date: Wed, 18 May 2016 12:12:01 +0200 Subject: fix issue 4181. add testcase. --- lib/system/sysstr.nim | 7 +++++-- tests/float/tfloat5.nim | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/float/tfloat5.nim 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 -- cgit 1.4.1-2-gfad0