• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Primitive Data Value Equality

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this question. Will we see something like this on the certification test? Can we assume that all floating point arithmetic will produce a false equality test?

The output looks like this:
.3333333
.33333334
false
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Leo! I'm assuming that you're talking about the SCJP. Yes, I would assume that you would never want to use a floating-point number for an equality test. However, I've never heard anyone say that you need to know this type of stuff for the test.
Also, a better forum for this question would be the Programmer Certification Study forum. It's the best test forum that I've used.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we assume that all floating point arithmetic will produce a false equality test?
No, definitely not. You can assume that any floating-point equality test may give a false result even though true is expected - but it also may give true. You're not expected to be able to predict the result in a case like the one you showed. You should know that a -b/c is approximately 1/3, and a/c is also approximately 1/3 , and that these two approximations may or may not be equal to each other.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic