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: Sin returns value not in [-1, 1] for very large values #7110

Closed
gopherbot opened this issue Jan 13, 2014 · 3 comments
Closed

math: Sin returns value not in [-1, 1] for very large values #7110

gopherbot opened this issue Jan 13, 2014 · 3 comments

Comments

@gopherbot
Copy link

by zhuwl08:

I'm using go version go1.2 darwin/amd64, but the issue still exists in the latest go src.

Here is the demo code:

http://play.golang.org/p/K4Fc8ts24u

{{{
a := 387001390666326231482368.000000
fmt.Printf("Sin(a) = %e\n", math.Sin(a))
}}}

The output is 

{{{
Sin(a) = 6.944847e+296
}}}

I know that for a large float, it's hard to get the accurate value for math.Sin, but I
expected that the return value should be in range [-1, 1], at least, which I rely on to
produce a reasonable value for other input.
@minux
Copy link
Member

minux commented Jan 16, 2014

Comment 1:

the sin implementation in the math package might return meaningless if x > 2**49 (which
is 5.6e14).
I wonder if it's worthwhile to switch to the msun library.

Labels changed: added release-none, repo-main.

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 2:

The problem is due to catastrophic errors introduced during argument reduction. There's
very little literature besides the classic Payne & Hanek argument reduction paper:
Payne & Hanek: "Radian reduction for trigonometric functions"
http://dl.acm.org/citation.cfm?id=1057602 (ACM paywall)
Sun's implementation:
K. C. Ng, "Argument Reduction for Huge Arguments: Good to the Last Bit"
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.67.5616&rep=rep1&type=pdf and:
http://www.validlab.com/arg.txt
A newer approach:
http://www.imada.sdu.dk/~kornerup/papers/RR2.pdf
http://perso.ens-lyon.fr/jean-michel.muller/RangeReductionIEEETC0305.pdf

@griesemer
Copy link
Contributor

Comment 3:

Status changed to Duplicate.

Merged into issue #6794.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants