summary refs log tree commit diff stats
path: root/lib/pure/strformat.nim
diff options
context:
space:
mode:
authorskilchen <skilchen@users.noreply.github.com>2018-06-05 06:09:07 +0200
committerVarriount <Varriount@users.noreply.github.com>2018-06-05 00:09:07 -0400
commit230692a22f92ed010e04ba8c1b2b95f86350f1a5 (patch)
tree6d874783342c6fc578b197a6685ff2ba7f12a891 /lib/pure/strformat.nim
parentfd102f39bb8c969d33015654422ff4541f211b51 (diff)
downloadNim-230692a22f92ed010e04ba8c1b2b95f86350f1a5.tar.gz
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
Diffstat (limited to 'lib/pure/strformat.nim')
-rw-r--r--lib/pure/strformat.nim7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/pure/strformat.nim b/lib/pure/strformat.nim
index 3e7b043ce..36404cdf7 100644
--- a/lib/pure/strformat.nim
+++ b/lib/pure/strformat.nim
@@ -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