]> Cypherpunks.ru repositories - gostls13.git/commitdiff
math: fix ternary correction statement in Log1p
authorBrian Kessler <brian.m.kessler@gmail.com>
Thu, 3 Jan 2019 17:00:49 +0000 (10:00 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 7 Jan 2019 18:57:45 +0000 (18:57 +0000)
The original port of Log1p incorrectly translated a ternary statement
so that a correction was only applied to one of the branches.

Fixes #29488

Change-Id: I035b2fc741f76fe7c0154c63da6e298b575e08a4
Reviewed-on: https://go-review.googlesource.com/c/156120
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/math/all_test.go
src/math/log1p.go

index c2d2efcd97fd3c0dd50e0cea373dd37fd72cca2f..ed42941780973a27b2f747757809c02fcada849f 100644 (file)
@@ -1528,6 +1528,7 @@ var vflog1pSC = []float64{
        0,
        Inf(1),
        NaN(),
+       4503599627370496.5, // Issue #29488
 }
 var log1pSC = []float64{
        NaN(),
@@ -1537,6 +1538,7 @@ var log1pSC = []float64{
        0,
        Inf(1),
        NaN(),
+       36.04365338911715, // Issue #29488
 }
 
 var vfmodfSC = []float64{
index b128a1620c880eb524fab7a603b9b82db7b8fb06..c4ec61b2259ebdf431d59c9b4911a1fce69554c1 100644 (file)
@@ -151,12 +151,13 @@ func log1p(x float64) float64 {
                        u = 1.0 + x
                        iu = Float64bits(u)
                        k = int((iu >> 52) - 1023)
+                       // correction term
                        if k > 0 {
                                c = 1.0 - (u - x)
                        } else {
-                               c = x - (u - 1.0) // correction term
-                               c /= u
+                               c = x - (u - 1.0)
                        }
+                       c /= u
                } else {
                        u = x
                        iu = Float64bits(u)