Search code examples
cfloating-pointfloating-accuracyprocessor

Is float value guaranteed to be 0 when a float variable is initialized to 0.0?


In C, on any micro controller when we initialize a float variable to 0

float var = 0.0f;

Is 'var' exactly equal to zero or does it depend on the min & max float resolution of the processor?


Solution

  • Happily, zero is actually zero no matter what: IEEE-754 (the usual standard for floats) sets aside the all-zeroes bit pattern as meaning identically zero.