Merge pull request #4182 from Parashurama/fix_issue_4181

fix issue #4181. add testcase.
This commit is contained in:
Andreas Rumpf
2016-05-18 12:42:43 +02:00
2 changed files with 20 additions and 2 deletions

View File

@@ -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'}:

15
tests/float/tfloat5.nim Normal file
View File

@@ -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