Reputation: 2125
Currently, I am transmitting a denormalized float number = 0x00300000. Before this value is set for another variable, inequality (var != var) check is done i.e. check for NaN. The inequality check fails for the denormalized number and the number is detected as NaN.
Could you please tell me what I am doing wrong here? My code is in C.
Thanks.
Upvotes: 0
Views: 1008
Reputation: 882806
The equality check seems fine on my system:
#include <stdio.h>
#include <string.h>
int main(void) {
int i = 0x00300000;
float f = 0;
if (sizeof(f) != sizeof(i)) {
printf ("Urk!\n");
return 1;
}
memcpy (&f, &i, sizeof(f));
printf ("%.50f\n", f);
if (f == f)
puts ("Equal");
else
puts ("Not equal");
return 0;
}
This outputs:
0.00000000000000000000000000000000000000440810381558
Equal
Upvotes: 2