0
Plz look at the following code and answer why its happening??
Is same value of float is less than double? Run code for different values (specially 0.5 , 0.7, 0.9, 0.4) https://code.sololearn.com/c6Ru8kPquUOk/?ref=app https://code.sololearn.com/c6Ru8kPquUOk/?ref=app
8 Respostas
+ 1
Yes. Default type of precision numbers are double not float. You comparing float with double which is higher type So not same. Float require 4bytes while double occupies 8bytes
Dnyaneshwar got it?
+ 1
Yes absolutely correct but when I run code for 0.5 and 0.6, 0.7 it's showing contradictory answer with theory. Plz explain??
+ 1
https://code.sololearn.com/c1dvpsoA6aqz/?ref=app
look at this code for double comparition
+ 1
https://code.sololearn.com/c6Ru8kPquUOk/?ref=app
As of your answer my code should print hello. But it's printing Good.
+ 1
Dnyaneshwar my point to is when you compre with float value with direct decimal number, they not same
like 0.7 is default double type.
float is less compare to double..
a=0.7f
a<0.7 is true
and for 0.8
it is happening because of compiler specific..
and am confused wait please....
+ 1
Dnyaneshwar
Ok. I referred others ,to give you a better answer. That's why some delay...
With refference from Gawen Steasy and ~swim~ :
Answer is floating point comparisons are unpredictable , different compiler produce different results. because it is compiler implementation specific...
0.6, 0.7 all are by default double values...
here in your case,
Odd.
0.9
It is checking,
if a<0.9
i.e 0.899999762<0.9
Even....
0.8
It is checking
if a<0.8
i.e 0.80000000<0.800000119
https://code.sololearn.com/cKii0a2b11M9/?ref=app
if you still need some other details mention here...
0
Thank you Jaya krishna . Fully satisfied with your answer. Thanks for helping đ
0
Dnyaneshwar Wel come..