Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #6834
| Date | 2011-08-06 14:51 -0700 |
|---|---|
| From | Patricia Shanahan <pats@acm.org> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: higher precision doubles |
| References | <j1hqc1$1ch$1@news.albasani.net> <strictfp-20110806003831@ram.dialup.fu-berlin.de> <j1k4db$1n2$1@news.albasani.net> |
| Message-ID | <OrWdncbuf7nLKqDTnZ2dnUVZ_vKdnZ2d@earthlink.com> (permalink) |
On 8/6/2011 12:24 PM, Jan Burse wrote:
> Stefan Ram schrieb:
>> Jan Burse<janburse@fastmail.fm> writes:
>>> IEEE allows to internally calculate with additional bits.
>>> Is it possible to have awailable these ops? Like an add
>>> with this higher precision? How could we store such a
>>> result? Would there be a wrapper like Double?
>>
>> See also:
>>
>> http://en.wikipedia.org/wiki/Strictfp
>>
>> .
>>
>
> Motivating example, in Go we have:
>
> func main() {
> x := math.Sin(2*math.Pi)
> fmt.Printf("x = %.30f, is zero = %v\n", x, x == 0)
> }
>
> x = 0.000000000000000000000000000000, is zero = true
>
> In Java we have:
>
>
> public static double zero1() {
> return Math.sin(2*Math.PI);
> }
>
> public static double zero2() {
> return StrictMath.sin(2*StrictMath.PI);
> }
>
> public static void main(String[] args) {
> System.out.println("zero1="+zero1());
> System.out.println("zero2="+zero2());
> }
>
> zero1=-2.4492935982947064E-16
> zero2=-2.4492935982947064E-16
I'm not sure I understand how this motivates extra precision. Would you
have been happier if the result had been something order 10^-24? Or if
this particular calculation had got 0, but some other even multiple of
PI had got an order 10^-24 result?
There are two issues here, algorithm and arithmetic precision. I do not
know exactly how Java calculates sin, but the usual approach is to have
a polynomial approximation for a range of angles close to zero, and a
reduction algorithm that maps calculating the sin of a general angle to
calculating the sin of an angle in that range (possibly with a need to
negate the result).
In this case the difference is most likely in the reduction step - if it
had produced 0, the sin result would have been 0.
Without a change in the algorithm, or its objective, I do not think
extra precision would eliminate all cases of this sort of difference.
Patricia
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next 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