Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6836
| From | Jan Burse <janburse@fastmail.fm> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: higher precision doubles |
| Date | 2011-08-07 00:57 +0200 |
| Organization | albasani.net |
| Message-ID | <j1kgtg$s7g$1@news.albasani.net> (permalink) |
| References | <j1hqc1$1ch$1@news.albasani.net> <strictfp-20110806003831@ram.dialup.fu-berlin.de> <j1k4db$1n2$1@news.albasani.net> <OrWdncbuf7nLKqDTnZ2dnUVZ_vKdnZ2d@earthlink.com> |
Patricia Shanahan schrieb:
> In this case the difference is most likely in the reduction step - if it
> had produced 0, the sin result would have been 0.
>
I guess 2*pi is "exact" in the sense that the operation * itself
has no loss, since we only need to adjust the exponent.
I forget to mention, we also get a non-zero value for sin(pi)
in Java, and not only for sin(2*pi).
Easiest reduction is sin(x) = cos(x-pi/2). But this reduction
seems not to be used:
double x=Math.PI;
System.out.println("pi="+x+", sin(pi)="+Math.sin(x));
x=Math.PI-Math.PI/2;
System.out.println("pi-pi/2="+x+", cos(pi-pi/2)="+Math.cos(x));
x=Math.PI/2;
System.out.println("pi/2="+x+", cos(pi/2)="+Math.cos(x));
Gives:
pi=3.141592653589793, sin(pi)=1.2246467991473532E-16
pi/2=1.5707963267948966, cos(pi/2)=6.123233995736766E-17
pi-pi/2=1.5707963267948966, cos(pi-pi/2)=6.123233995736766E-17
So it seems that the error in PI representation seems the
only reason to be not to return zero. So we have sin(x) with
x approximating pi. The error is:
sin(x) - sin(pi) = sin(pi+(x-pi)) - 0.
= - sin(x-pi)
~ - (x - pi)
= pi - x
So I guess the PI representation is below the real pi. Since
we get a positive result for sin(x). Lets check:
Java PI:
3.141592653589793
real pi:
3.141592653589793238462643383...
Difference:
0.000000000000000238462643383...
Well the above idea does also not work, we only get:
x=0.000000000000000238462643383;
System.out.println("PI-pi="+x+", sin(PI-pi)="+Math.sin(x));
PI-pi=2.38462643383E-16, sin(PI-pi)=2.38462643383E-16
But not 1.2246467991473532E-16. But we can try a fully exact decimal
development of the approximate machine PI. Using the double to
BigDecimal conversion we get (a thing I like most with the
BigDecimal package):
System.out.println("PI="+new BigDecimal(Math.PI));
PI=3.141592653589793115997963468544185161590576171875
Therefore:
Java PI:
3.141592653589793115997963468...
real pi:
3.141592653589793238462643383...
Difference:
0.000000000000000122464679915...
Everything fits perfectly.
Question is why Go gets zero?
Bye
Small-angle Approximation taken from here:
http://en.wikipedia.org/wiki/Small-angle_approximation
Additional PI Digits taken from here:
http://en.wikipedia.org/wiki/Pi
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 00:20 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 03:35 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 13:03 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 12:20 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 23:30 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 16:12 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:35 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-06 19:26 -0700
Re: higher precision doubles supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-09 00:42 -0400
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-09 04:07 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 14:00 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-09 09:07 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-10 08:50 +0200
Re: higher precision doubles supercalifragilisticexpialadiamaticonormalizeringelimatisticantations <supercalifragilisticexpialadiamaticonormalizeringelimatisticantations@averylongandannoyingdomainname.com> - 2011-08-10 20:16 -0400
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 10:11 -0500
Re: higher precision doubles Arne Vajhøj <arne@vajhoej.dk> - 2011-08-09 22:40 -0400
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-09 22:06 -0500
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-10 08:53 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 21:24 +0200
Re: higher precision doubles markspace <-@.> - 2011-08-06 13:29 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-06 23:20 +0200
Re: higher precision doubles markspace <-@.> - 2011-08-06 15:43 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:06 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 16:21 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:34 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 21:32 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 17:24 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 17:39 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-07 09:26 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 21:23 +0200
Re: higher precision doubles Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-07 20:48 -0400
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 09:05 +0200
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-08 05:37 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:08 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:16 +0200
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-08 19:29 +0200
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:34 -0500
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-08 13:49 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 01:08 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-09 02:44 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-09 12:52 +0200
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-09 13:15 -0700
Re: higher precision doubles BGB <cr88192@hotmail.com> - 2011-08-07 13:51 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 01:59 +0200
Re: higher precision doubles Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-08-08 21:03 -0500
Re: higher precision doubles Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-06 17:33 -0400
Re: higher precision doubles Patricia Shanahan <pats@acm.org> - 2011-08-06 14:51 -0700
Re: higher precision doubles Jan Burse <janburse@fastmail.fm> - 2011-08-07 00:57 +0200
csiph-web