]> Cypherpunks.ru repositories - gostls13.git/commitdiff
strconv: fix Eisel-Lemire for negative zero
authorNigel Tao <nigeltao@golang.org>
Thu, 22 Oct 2020 12:59:00 +0000 (23:59 +1100)
committerNigel Tao <nigeltao@golang.org>
Thu, 22 Oct 2020 21:12:43 +0000 (21:12 +0000)
This is somewhat academic (and no tests failed before this commit),
since func atof64 only calls func eiselLemire when func atof64exact
fails, and func atof64exact doesn't fail when parsing positive or
negative zeroes. But it's still worth fixing.

Change-Id: Ibe6ef4c8fd96827673b711d5456003fbc447e39c
Reviewed-on: https://go-review.googlesource.com/c/go/+/264140
Trust: Nigel Tao <nigeltao@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/strconv/eisel_lemire.go

index 00fadbdb96a43909cd96a84f71163c48407d9280..5cd22a7e371fd6ac5e3a7c854d11fdc8e2e25471 100644 (file)
@@ -22,14 +22,17 @@ import (
        "math/bits"
 )
 
-func eiselLemire(man uint64, exp10 int, neg bool) (ret float64, ok bool) {
+func eiselLemire(man uint64, exp10 int, neg bool) (f float64, ok bool) {
        // The terse comments in this function body refer to sections of the
        // https://nigeltao.github.io/blog/2020/eisel-lemire.html blog post.
 
        // Exp10 Range.
        const exp10Min, exp10Max = -307, +288
        if man == 0 {
-               return 0, true
+               if neg {
+                       f = math.Float64frombits(0x80000000_00000000) // Negative zero.
+               }
+               return f, true
        }
        if exp10 < exp10Min || exp10Max < exp10 {
                return 0, false