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: hyperbolic sinh, cosh and tanh give wrong result for Inf input #29320

Open
kortschak opened this issue Dec 18, 2018 · 8 comments

Comments

@kortschak
Copy link
Contributor

@kortschak kortschak commented Dec 18, 2018

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

$ go version
go version go1.11.4 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
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"

What did you do?

Run the code at https://play.golang.org/p/8dz30xSTLdI.

Notice that sinh(inf) and cosh(inf) are inf, and tanh(inf) is 1.

What did you expect to see?

sinh((+Inf+Infi)) -> (+Inf+Infi)
cosh((+Inf+Infi)) -> (+Inf+Infi)
tanh((+Inf+Infi)) -> (1+0i)

What did you see instead?

sinh((+Inf+Infi)) -> (NaN+NaNi)
cosh((+Inf+Infi)) -> (NaN+NaNi)
tanh((+Inf+Infi)) -> (NaN+NaNi)
@ALTree ALTree added this to the Go1.13 milestone Dec 18, 2018
@bmkessler

This comment has been minimized.

Copy link
Contributor

@bmkessler bmkessler commented Dec 18, 2018

I would recommend conforming to the C99 Standard Appendix G.6 for complex arithmetic which differs slightly from the expected results above.

csinh(+∞ + i∞) returns ±∞ + iNaN (where the sign of the real part of the result is
unspecified) and raises the ‘‘invalid’’ floating-point exception
ccosh(+∞ + i∞) returns ±∞ + iNaN (where the sign of the real part of the result is
unspecified) and raises the ‘‘invalid’’ floating-point exception.
ctanh(+∞ + i∞) returns 1 ± i0 (where the sign of the imaginary part of the result is
unspecified).

Likely other special cases may not be handled consistent with the C99 standard either.

@kortschak

This comment has been minimized.

Copy link
Contributor Author

@kortschak kortschak commented Dec 19, 2018

Yes, those seem most reasonable. Note that cmplx.IsInf(±∞ + iNaN) is true.

@kortschak

This comment has been minimized.

Copy link
Contributor Author

@kortschak kortschak commented Dec 19, 2018

See also cmplx.Sqrt which gives sqrt((+Inf+Infi)) -> (+Inf+NaNi). The C99 standard says, "csqrt(x+i∞) returns +∞+i∞, for all x (including NaN)."

So, yes. Others are not consistent with C99 either.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Dec 20, 2018

@kortschak

This comment has been minimized.

Copy link
Contributor Author

@kortschak kortschak commented Feb 5, 2019

Also cmplx.Pow behaves differently to math.Pow when raising NaN**0.

https://play.golang.org/p/b5zuzP7j7nk

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 27, 2019

Change https://golang.org/cl/169501 mentions this issue: math/cmplx: handle special cases

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
@gopherbot gopherbot closed this in 68dce42 Nov 7, 2019
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 8, 2019

Change https://golang.org/cl/206037 mentions this issue: Revert "math/cmplx: handle special cases"

gopherbot pushed a commit that referenced this issue Nov 8, 2019
This reverts CL 169501.

Reason for revert: The new tests fail at least on s390x and MIPS. This is likely a minor bug in the compiler or runtime. But this point in the release cycle is not the time to debug these details, which are unlikely to be new. Let's try again for 1.15.

Updates #29320
Fixes #35443

Change-Id: I2218b2083f8974b57d528e3742524393fc72b355
Reviewed-on: https://go-review.googlesource.com/c/go/+/206037
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@bradfitz bradfitz reopened this Nov 8, 2019
@bradfitz

This comment has been minimized.

Copy link
Member

@bradfitz bradfitz commented Nov 8, 2019

As @ianlancetaylor wrote on the revert:

Reason for revert: The new tests fail at least on s390x and MIPS. This is likely a minor bug in the compiler or runtime. But this point in the release cycle is not the time to debug these details, which are unlikely to be new. Let's try again for 1.15.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.