Sunday, February 3, 2013

Float variables dilemma, C/C++

I came across an amazing post. Guess what will be the answer of following program:

float fx = 4.5;
if ( fx != 4.5)
      printf(" WTH ? Something wrong with assignment");

If you expect that WTH?... won't be printed ever then check this link doubles-are-not-floats-so-dont-compare-them

Link: floating-point-gui.de/errors/comparison/

Very nice post related to floating values.

Float: These are the single precision variables occupying 4 bytes (32 bits) with 24 bits for mantissa or significant part.
Double: These are the double precision variables occupying 8 bytes (64 bits) with 53 bits reserved for mantissa.

Min Value of float in C#: Single.MinValue

No comments:

Post a Comment