www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: nan question

reply bobef <bobef abv_nospam.bg> writes:
Janice Caron Wrote:

 On 9/25/07, bobef <bobef abv_nospam.bg> wrote:
 something is totally wrong. Just look at this. "!<>="

Well consider, the imaginary number i is not less than one. It is also not greater than one. It is also not equal to one. It makes perfect sense.

I can't imagine such number, sorry :) But let aside my imagination. I don't know what imaginary number is, so I am not commenting if it makes sense. All I'm saying it that it is nonsense that if(double.nan!=double.nan) returns false (IMHO).
Sep 25 2007
next sibling parent reply Nathan Reed <nathaniel.reed gmail.com> writes:
bobef wrote:
 Janice Caron Wrote:
 
 On 9/25/07, bobef <bobef abv_nospam.bg> wrote:
 something is totally wrong. Just look at this. "!<>="

not greater than one. It is also not equal to one. It makes perfect sense.

I can't imagine such number, sorry :) But let aside my imagination. I don't know what imaginary number is, so I am not commenting if it makes sense. All I'm saying it that it is nonsense that if(double.nan!=double.nan) returns false (IMHO).

I'm assuming you meant to say that it makes no sense if double.nan == double.nan returns false? But if NaNs compared equal to each other, then this: sqrt(-1) == acos(2) would be true, since both return a NaN. I bet you don't really want that. Thanks, Nathan Reed
Sep 25 2007
next sibling parent reply Don Clugston <dac nospam.com.au> writes:
Nathan Reed wrote:
 bobef wrote:
 Janice Caron Wrote:

 On 9/25/07, bobef <bobef abv_nospam.bg> wrote:
 something is totally wrong. Just look at this. "!<>="

not greater than one. It is also not equal to one. It makes perfect sense.

I can't imagine such number, sorry :) But let aside my imagination. I don't know what imaginary number is, so I am not commenting if it makes sense. All I'm saying it that it is nonsense that if(double.nan!=double.nan) returns false (IMHO).

I'm assuming you meant to say that it makes no sense if double.nan == double.nan returns false? But if NaNs compared equal to each other, then this: sqrt(-1) == acos(2) would be true, since both return a NaN. I bet you don't really want that.

Yup, that's the reasoning. Even so, I think it probably was a mistake by the IEEE standard to violate x == x; I think the problems created by this decision are worse than the ones that were solved. (Note that they could even have used NaN payloads to detect the worst kinds of errors). But it's built into the hardware everywhere, so it's Too Late Now.
Sep 25 2007
parent Don Clugston <dac nospam.com.au> writes:
Janice Caron wrote:
 Think of NaN as meaning "I don't know the answer".
 
 With that understanding, when you compare two NaNs with ==, you are
 asking "Is one thing I don't know the answer to equal to another thing
 I don't know the answer to". The absolutely correct answer should
 really be "I don't know, but probably not", but since that can't be
 expressed in a bool, we go with the second best answer: no.

Yes, we're forcing 3 states (yes, no, maybe) into 2 states. IMHO, it would have been better to retain the crucial identity x==x, rather than try to detect obscure floating-point bugs. (and introduce a different operator to mean, equal-and-not-both-NaN). I use NaNs a lot (probably more than anyone else on this ng), and have not found many cases where the IEEE behaviour is helpful.
Sep 26 2007
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
Think of NaN as meaning "I don't know the answer".

With that understanding, when you compare two NaNs with ==, you are
asking "Is one thing I don't know the answer to equal to another thing
I don't know the answer to". The absolutely correct answer should
really be "I don't know, but probably not", but since that can't be
expressed in a bool, we go with the second best answer: no.
Sep 26 2007
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"bobef" <bobef abv_nospam.bg> wrote in message 
news:fdbedv$2pu2$1 digitalmars.com...
 Janice Caron Wrote:

 On 9/25/07, bobef <bobef abv_nospam.bg> wrote:
 something is totally wrong. Just look at this. "!<>="

Well consider, the imaginary number i is not less than one. It is also not greater than one. It is also not equal to one. It makes perfect sense.

I can't imagine such number, sorry :) But let aside my imagination. I don't know what imaginary number is, so I am not commenting if it makes sense. All I'm saying it that it is nonsense that if(double.nan!=double.nan) returns false (IMHO).

From what I can recall reading on this message board, the behavior is exactly described as correct in the IEEE standard. Therefore, the answer is that the behavior works as designed. You need to address the rediculousness of it with the IEEE committee that designed the standard :) -Steve
Sep 25 2007
prev sibling next sibling parent BCS <ao pathlink.com> writes:
Reply to bobef,

 All I'm saying it that it is nonsense that
 if(double.nan!=double.nan) returns false (IMHO).
 

NaN is "Not A Number" and considering that we are talking about numeric equality, it is reasonable for something that isn't a NUMber to not be NUMerically equal to anything. It is sort of like comparing to nothing (not the state of nothing or a set of nothing, but the absolute omission or the entity) this assertion "x is equal to" is syntactically broken so how can it be true?
Sep 25 2007
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"bobef" <bobef abv_nospam.bg> wrote in message 
news:fdbedv$2pu2$1 digitalmars.com...
 I can't imagine such number, sorry :) But let aside my imagination. I 
 don't know what imaginary number is

An imaginary number is an ifloat, idouble, or ireal. ;) (Everything I know I learned from D.)
Sep 25 2007