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

Closed
kortschak opened this issue Dec 18, 2018 · 9 comments
Closed
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@kortschak
Copy link
Contributor

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 18, 2018
@ALTree ALTree added this to the Go1.13 milestone Dec 18, 2018
@bmkessler
Copy link
Contributor

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
Copy link
Contributor Author

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

@kortschak
Copy link
Contributor Author

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
Copy link
Contributor

bcmills commented Dec 20, 2018

CC @griesemer

@kortschak
Copy link
Contributor Author

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

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

@gopherbot
Copy link

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
Copy link

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
Copy link
Contributor

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.

@gopherbot
Copy link

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

xujianhai666 pushed a commit to xujianhai666/go-1 that referenced this issue May 21, 2020
Implement special case handling and testing to ensure
conformance with the C99 standard annex G.6 Complex arithmetic.

Fixes golang#29320

Change-Id: Id72eb4c5a35d5a54b4b8690d2f7176ab11028f1b
Reviewed-on: https://go-review.googlesource.com/c/go/+/220689
Reviewed-by: Robert Griesemer <gri@golang.org>
@golang golang locked and limited conversation to collaborators May 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted 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

8 participants