Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #6890

Re: higher precision doubles

From Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: higher precision doubles
Date 2011-08-08 21:03 -0500
Organization A noiseless patient Spider
Message-ID <j1q4hj$qmm$1@dont-email.me> (permalink)
References <j1hqc1$1ch$1@news.albasani.net> <strictfp-20110806003831@ram.dialup.fu-berlin.de> <j1k4db$1n2$1@news.albasani.net> <j1k87t$kol$1@dont-email.me> <j1kb73$h3p$1@news.albasani.net>

Show all headers | View raw


On 8/6/2011 4:20 PM, Jan Burse wrote:
> And BTW the negative sign in front of the zero anyway indicates
> that some rounding was going on, and not a true zero was returned
> by the computation. And you could try x == 0 || x == -0, if this
> is possible, and you would still get false.

Several notes:
1. 0 is an integer, so -0 == 0.
2. 0.0 == -0.0 is still true, since both positive and negative zero 
compare as equals. Figuring out how to distinguish between the two can 
get really aggravating if you have one of the few cases where it 
actually, truly matters.
3. Java still prints -0.0 (floating point numbers are signed magnitude 
and therefore have both +0.0 and -0.0). And there are cases where -0.0 
can come up without rounding: -1/Infinity is a classic one, as is the 
"other" boundary in trigonometric cases. You can get a -0.0 without it 
being the result of an underflow in negative numbers.
4. Don't compare equal to a floating point number, with the possible 
exception of 0/Infinity/NaN (that's a fun one [1]!) to test for possible 
overflow/underflow/invalid input cases.

[1] NaN is defined in IEEE 754 such that it fails all comparison tests. 
Which means NaN < 0, NaN > 0, and, most bizarrely, NaN != NaN. So x == 
NaN will never return true.
-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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