OCPJP
OCPJP
Stephan van Hulst wrote:
Let's use 124.4 as an example. The values I use here are made up, and are not correct:
If you assign 124.4f to f, it might actually store the value 124.400012. Since doubles have higher precision, the value you store to d might actually be 124.4000000005.
As you can see, these values are not the same, so == comparison will return false.
The float value is larger than the double value, so this explains the rest of the comparisons as well.
SCJP 6. Learning more now.
Andreas Svenkson wrote:Is it safe to assume that any float and double assigned the same value will never be the same?
Dennis Deems wrote:
Andreas Svenkson wrote:Is it safe to assume that any float and double assigned the same value will never be the same?
Try Rahul's demo with the value 124.5
Andreas Svenkson wrote:
Dennis Deems wrote:
Andreas Svenkson wrote:Is it safe to assume that any float and double assigned the same value will never be the same?
Try Rahul's demo with the value 124.5
Indeed.... man I hope there won't be any questions of this type on the test, it's about as close to impossible to answer as it can get.
// Andreas
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Mala Gupta wrote:If the decimal part of float/ double is 0, then the literal values are equal. Examine the following code:
cheers
Mala
Rahul Sudip Bose wrote:How do i know the exact value stored in a float, Float etc?
Andreas Svenkson wrote:Is it safe to assume that any float and double assigned the same value will never be the same? Theoretically there should be a chance that it can sometimes be the same, but obviously we can't ever know when that is the case and most of the time I would guess it isn't?
Mala Gupta wrote:If the decimal part of float/ double is 0, then the literal values are equal.
Stephan van Hulst wrote:
Both literals imply the integer value 10^20, but the comparison evaluates to false.
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
If debugging is the process of removing bugs, then programming must be the process of putting them in. -- Edsger Dijkstra
Stephan van Hulst wrote:[E]xcept instead of 3 digits of precision, float has 32 bits of precision, and double has 64 bits of precision.
Prepare for 'OCA Java SE 8 certification' with eJavaGuru.com
Author of Manning's OCA Java SE 8 bookProgrammer I Certification Guide, OCA Java SE 7 Programmer I Certification Guide and OCP Java SE 7 Programmer II Certification Guide
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
|