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 · 4 comments

Comments

Projects
None yet
4 participants
@kortschak
Copy link
Contributor

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

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

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 commented Dec 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment