I'm finding my float value has changed after being returned. I output the hex value of the float before being returned and then after it gets returned. I expect the HEX output to be identical but they have changed. Can you please explain why this is happening and how do I prevent this from happening?
Thanks!
#include <stdio.h>
typedef int uint32;
typedef unsigned char uint8;
static const float CONST_FLOAT = 150.36e6;
uint32 foo( uint8 param ) {
return 1;
}
float get_float( uint8 param )
{
float fVal = 0.0;
fVal = (foo( param )*1.0) / ( 60.0 * CONST_FLOAT );
printf("fVal = 0x%X\n", fVal);
printf("fVal = %f\n", fVal);
return fVal;
}
int main(void) {
float fTest;
fTest = get_float(1);
printf("fTest = 0x%X\n",fTest);
printf("fTest = %f\n",fTest);
return;
}
OUTPUT: fVal = 0x6A96C728 fVal = 0.000000
fTest = 0x9AAF9000 fTest = 0.000000
I expect the fVal displayed in Hex format to be the same as fTest in Hex but they turned out different why is that?
Thanks!