| Author |
difference between float value and float value with casting
|
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
what is the difference in these 2 statements ?what's happening in internally?
|
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
The first 6.5 is a double, the round() that takes a double argument is invoked. The second one is a float, and the round() that takes a float is called. In both cases, the subtraction is done by the compiler at compile-time, so round() is invoked directly. The reason the second one prints "false" is because a float is only 32 bits, and doesn't have the precision to distinguish between MIN_VALUE-6.5 and MIN_VALUE; they're not far enough apart on the number line. Double, on the other hand, is 64 bits, and can indeed distinguish between these values.
|
[Jess in Action][AskingGoodQuestions]
|
 |
 |
|
|
subject: difference between float value and float value with casting
|
|
|