In C, the literal “5.9” has type double
and is converted by common compilers to 5.9000000000000003552713678800500929355621337890625, because they use binary IEEE-754 floating point, and that number is the value representable as a double
that is closest to 5.9. Your code initializes a float
with that value. That requires converting a double
to a float
, and the result is 5.900000095367431640625, because that is the float
value that is closest to the double
value. Obviously, the latter is greater than the former, which is why your output is “Greater than”.
With .9, the literal “.9” is converted to the double
0.90000000000000002220446049250313080847263336181640625. Then that double
is converted to the float
0.89999997615814208984375, which is obviously less than the double
.