• 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

why Integer is behaving differently ??

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
Can somebody pls explain me about the output of below code.

Output of above code is
equal unequal equal equal equal

why Integer.MAX_VALUE compare method is displaying unequal ?
Cheers
Raju

(Added code tags - Barry)
[ April 18, 2004: Message edited by: Barry Gaunt ]
 
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
Floating-point values are not exact; they're represented in a fixed number of bits which, for float, is smaller than the number of bits needed to represent Integer.MAX_VALUE exactly. Therefore, the float value will be "rounded" to the nearest representable value. double, though, does have enough bits to represent this value, so it will contain the exact value. Thus, the two variables will contain different numbers.
For Long.MAX_VALUE, neither float nor double has enough bits to represent the value exactly; it's just luck, I think, that the rounded values are the same for both float and double.
 
Raju Sri
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,
Thanks for your explanation.
Raju
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep 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