• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparison with NaN

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is this comparison false?



Just because?
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say just because that are both NaN doesn't make the equal. Lots and Lots of things are NaN (a, b, c, d) but are not equal.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, just because -- or as we computer sciency type fellas like to say, "by definition." The Java Lanaguage Specificiation explicitly states that NaN is not equal to anything, including itself.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think for the same reason the two strings in the following code are not equal:

In other words, you have two different objects that are identical, but == compares whether the references are equal, and that's only true when the references refer to the same object.
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Specificiation explicitly states that NaN is not equal to anything, including itself.


That's the strange part.
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not really strange. It's specified in IEEE 754.
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
Yes, just because -- or as we computer sciency type fellas like to say, "by definition." The Java Lanaguage Specificiation explicitly states that NaN is not equal to anything, including itself.



If we compare with the inequality operator: != The comparison is true.

"By definition" is the only option.

If floating point division by zero is really not the same as whatever the value of java.lang.Double.NaN is, then what is the value of floating point division by zero? Did someone just choose to use the same "word"(NaN) to describe that value?
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by leo donahue:


If we compare with the inequality operator: != The comparison is true.

"By definition" is the only option.

If floating point division by zero is really not the same as whatever the value of java.lang.Double.NaN is, then what is the value of floating point division by zero? Did someone just choose to use the same "word"(NaN) to describe that value?



It depends on what the numerator is.

If the numerator and denominator are both 0, the result is NaN.

If the numerator is, for instance, 1.0, then 1.0/0 is Infinity.

As Tim pointed out, in the case of 0.0/0 != Double.NaN, just because two things are not numbers, they are not necessarily equal to each other.
[ October 16, 2006: Message edited by: Keith Lynn ]
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I meant both numerator and denominator.

I keep forgetting the slightest inference really takes the converstation in different directions. I'll try harder.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mathematically speaking, x/0 is undefined, not infinity. Where x is a real number, not zero. Infinity is not a number, but can basically be described as if there exists a one-to-one correspondence between that set and a proper subset of itself then the set is infinite.

If you have 1/x, then its value approaches infinity as x goes to zero, but 1/0 is not an infinite number, since infinity is not a number.

0/0 is indeterminant.
 
I child proofed my house but they still get in. Distract them with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic