+ 6
floats
why the result of bellow code is true while logically it seems to be false(cause they're equal)?! i know that an integer float(no number after decimal point) behave normally in comparisons but the problem starts as we add some numbers after the decimal point. for example: float a=0.8 if(0.8>a) printf("true"); else printf("false"); //output true
2 Antworten
+ 1
Read this....
https://www.sololearn.com/Discuss/2149084/?ref=app
+ 1
1)
0.8 is double (IEEE754 using 64 bits)
and
float a = 0.8; // IEEE754 using 32 bits
IEEE754 is the most common format used by computers to represent non-integer numbers...
2) They are stored as:
double 0.8: 0x3FE999999999999A
float 0.8: 0x3F4CCCCD
They are different numbers!
3) If we convert them to decimal :
double 0.8 -> 0.80000000000000004441
float 0.8 --> 0.80000001192092895508
>>> float 0.8 > double 0.8
:)