From 8b221092b9a9664918c28a76b109786956e0057d Mon Sep 17 00:00:00 2001 From: Charlie Dorian Date: Tue, 30 Jun 2015 20:14:30 -0400 Subject: [PATCH] math: Expm1 returns -1 with large negative argument. Fixes #11442 Change-Id: I2053fe752c6a122924d28565f1338f73e00ed417 Reviewed-on: https://go-review.googlesource.com/11791 Reviewed-by: David Chase Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer Reviewed-by: Ian Lance Taylor --- src/math/all_test.go | 4 ++++ src/math/expm1.go | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/math/all_test.go b/src/math/all_test.go index 84061be264..6286584e0c 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -946,16 +946,20 @@ var expSC = []float64{ var vfexpm1SC = []float64{ Inf(-1), + -710, Copysign(0, -1), 0, + 710, Inf(1), NaN(), } var expm1SC = []float64{ + -1, -1, Copysign(0, -1), 0, Inf(1), + Inf(1), NaN(), } diff --git a/src/math/expm1.go b/src/math/expm1.go index 8f56e15cc4..064e131161 100644 --- a/src/math/expm1.go +++ b/src/math/expm1.go @@ -158,11 +158,11 @@ func expm1(x float64) float64 { // filter out huge argument if absx >= Ln2X56 { // if |x| >= 56 * ln2 - if absx >= Othreshold { // if |x| >= 709.78... - return Inf(1) // overflow - } if sign { - return -1 // x < -56*ln2, return -1.0 + return -1 // x < -56*ln2, return -1 + } + if absx >= Othreshold { // if |x| >= 709.78... + return Inf(1) } } -- 2.50.0