mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 05:50:30 +00:00
Merge pull request #4182 from Parashurama/fix_issue_4181
fix issue #4181. add testcase.
This commit is contained in:
@@ -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
15
tests/float/tfloat5.nim
Normal 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
|
||||
Reference in New Issue
Block a user