Fix strformat neg zero (#7954)

* fix strformat handling of neg zero with sign

* better tests for neg zero with sign

* use inplace insertion of the sign as suggested by Varriount
This commit is contained in:
skilchen 2018-06-05 06:09:07 +02:00 • committed by Varriount
commit 230692a22f
2 changed files with 14 additions and 1 deletions

View file

@ -527,8 +527,13 @@ proc format*(value: SomeFloat; specifier: string; res: var string) =
var sign = false
if value >= 0.0:
if spec.sign != '-':
f = spec.sign & f
sign = true
if value == 0.0:
if 1.0 / value == Inf:
# only insert the sign if value != negZero
f.insert($spec.sign, 0)
else:
f.insert($spec.sign, 0)
else:
sign = true