How to check if a float is positive denormalized/negative denormalized or not denormalized.
I tried to do:
int is_denorm(float f)
{
unsigned int x = *(int*)&f;
unsigned expMask = (1 << 8) - 1;
expMask = expMask << 23;
//now needs to check if the exp is all zero how can I do it
}
Note that both C and IEEE-754 use subnormal and not denormal.
Avoid code like
*(int*)&f;andexpMask << 23, .... That runs into aliasing concerns,floatencoding issues and size ofunsigned.Sometimes 0.0 is desired to be classified like sub-normals
Code such as below works well too when NANs behave per IEEE-754 and fails
<comparisons, otherwise append a&& !isnan(x)to thereturn.