Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: Exp(x) function on amd64 can not return denormal numbers #23164

Closed
erifan opened this issue Dec 18, 2017 · 5 comments
Closed

math: Exp(x) function on amd64 can not return denormal numbers #23164

erifan opened this issue Dec 18, 2017 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@erifan
Copy link

erifan commented Dec 18, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

Go version devel +2de98eb Sat Dec 16 23:30:58 2017 +0000 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/username/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/username/golangworkspace"
GORACE=""
GOROOT="/home/username/golang"
GOTMPDIR=""
GOTOOLDIR="/home/username/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build362762432=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Add a test case: Exp(-740.0) for Exp(x) function, and verify the correctness of Exp(x) with commands:
cd golang/src/math/
../../bin/go test -c
./math.test -test.run TestExp$
Changes are as follow:

diff --git a/src/math/all_test.go b/src/math/all_test.go
index 0412c19..47cf947 100644
--- a/src/math/all_test.go
+++ b/src/math/all_test.go
@@ -1012,6 +1012,7 @@ var vfexpSC = []float64{
        1.48852223e+09,
        1.4885222e+09,
        1,
+       -7.40e+02,                           // The input parameters of Exp(x) function
 }
 var expSC = []float64{
        0,
@@ -1023,6 +1024,7 @@ var expSC = []float64{
        Inf(1),
        Inf(1),
        2.718281828459045,
+       4.2e-322,                             // The expected result of Exp(-740.0)
 }

 var vfexp2SC = []float64{

What did you expect to see?

PASS

What did you see instead?

--- FAIL: TestExp (0.00s)
all_test.go:2277: Exp(-740) = 0, want 4.2e-322
FAIL

@odeke-em
Copy link
Member

@erifan thank you for the report. I have modified your issue just to display your diff in markdown.

/cc @griesemer

@odeke-em odeke-em added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 18, 2017
@ALTree
Copy link
Member

ALTree commented Dec 18, 2017

This is a limitation of the algorithm used in the amd64 assembly implementation of Exp (the pure go version we use e.g. for 386 does not have this issue and correctly returns 4.2e-322). AFAIK it's not the only issue the amd64 implementation has. It's much faster than the pure go version, but accuracy-wise it's not as good. It has been like this since forever, anyway, it's not a recent regression.

@odeke-em
Copy link
Member

Thank you @ALTree! I'll mark this for Go1.11 then.

@odeke-em odeke-em added this to the Go1.11 milestone Dec 18, 2017
@gopherbot
Copy link

Change https://golang.org/cl/87337 mentions this issue: math: handle denormals in AMD64 Exp

@erifan erifan closed this as completed Mar 24, 2018
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 28, 2018
@griesemer
Copy link
Contributor

@erifan This has not been submitted yet. Re-opening. Once it's submitted, the issue will be closed automatically.

@griesemer griesemer reopened this Mar 28, 2018
@golang golang locked and limited conversation to collaborators Mar 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants