Part Number: TMS320F28335
I am recieving a float number from CAN bus, but the nubmer is smaller than F_MIN, about 1e-42, but as soon as I assign it to a long double or a float, it becomes 0. So I tried to use the following function to convert, but still the same result.
My compiler is very old, 6.1, and I use the FPU lib. Any ideas?
Thanks,
Nelson
long double f32bits_to_double(Uint32 bits)
{
Uint32 sign = bits >> 31;
Uint32 expo = (bits >> 23) & 0xFFu;
Uint32 mant = bits & 0x7FFFFFu;
long double v;
if (expo == 0u) {
/* zero or subnormal: value = mant * 2^-149 */
v = ldexp((long double)mant, -149);
} else if (expo == 0xFFu) {
v = mant ? NAN : INFINITY;
} else {
/* normal: value = (1.mant) * 2^(expo-127) */
v = ldexp((long double)(mant | 0x800000u), (int)expo - 127 - 23);
}
return sign ? -v : v;
}