Thursday, April 12, 2012

Float vs Double

Would I ever get an incorrect result if I promote 2 floats to double and do a 64bit comparison rather than a 32bit comparison?


1 comment:

  1. Yes, if the difference between them is beyond the precision of the float type.

    For example, say you have the two double values:


    and that the precision of a float was only four decimal digits. That would mean that the two float values would be 1.234 and 1.234, hence equal.

    The double values are not equal however.

    However, if you're talking about floats being cast to doubles, then identical floats should give you identical doubles.