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/cmplx: Tan is incorrect for large values along the real axis #31566

Closed
bmkessler opened this issue Apr 19, 2019 · 1 comment
Closed

math/cmplx: Tan is incorrect for large values along the real axis #31566

bmkessler opened this issue Apr 19, 2019 · 1 comment
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bmkessler
Copy link
Contributor

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

$ go version go1.12 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/bmkessler/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/bmkessler/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/bmkessler/dev/go/src/go.mod"
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-build347839563=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Attempt to calculate Tan for large values along the real axis

https://play.golang.org/p/7VcgDjysXb9

What did you expect to see?

cmplx.Tan(complex(1<<300, 0)) == (4.60901287677811+0i)

What did you see instead?

cmplx.Tan(complex(1<<300, 0)) == (-0-0i)

This is due to incorrect range reduction by Pi in reducePi.

Additionally, the threshold used in math/trig_reduce.go was not set conservatively enough, which affects both math and math/cmplx. The prior value ensured that catastrophic failure did not occur where the argument x would not actually be reduced below Pi/4. However, errors in reduction begin to occur at values much lower values when z = ((x - y*PI4A) - y*PI4B) - y*PI4C is not exact because y*PI4A cannot be exactly represented as a float64. For example:

math.Tan(1<<35) == 0.8427614121783361
But, the true value is 0.84276385870875983

An error in the sixth place.

@gopherbot
Copy link

Change https://golang.org/cl/172838 mentions this issue: math/cmplx: implement Payne-Hanek range reduction

@julieqiu julieqiu added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 22, 2019
@julieqiu julieqiu added this to the Go1.13 milestone Apr 22, 2019
@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@golang golang locked and limited conversation to collaborators Mar 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants