0
Please explain the following code?
will float 1.1 and double 1.1 will give same result? (ans. no). will float 1.5 and double 1.5 will give same result?(ans. yes)
3 Respuestas
+ 3
Some fractions of real numbers can not be represented or saved in binary format. So never compare doubles with the (default) equality operator. Instead use some approximation method where you can define the precision to compare two doubles with.
0.1 in decimal is 0.0001100110011.. period in binary, where you'd run out of memory before ever being able to store that number. So it gets cut off after several digits. When reverting from binary to decimal, you won't get the exact same number. Keep that in mind :)
+ 1
Yes they will
0
The precision in which fractional numbers (set R) can be represented is different. Hence the difference.