Home > front end >  Can floats not suport negative or even 0?
Can floats not suport negative or even 0?

Time:05-06

It's follow-up question to: float formula

C23 wording adds stronger assertion

ISO/IEC 9899:202x (E)

Floating types shall be able to represent zero (all fk == 0) and all normalized floating-point numbers (f1 > 0 and all possible k digits and e exponents result in values representable in the type

CodePudding user response:

If you speak about "floating point types" in general (and not about the type named float) when using the word "floats":

Yes:

If you design a compiler, you might define the non-standard type unsigned float with 24 mantissa bits, 8 exponent bits, no sign bit and 256 possible exponent values (instead of 254).

Such a floating point format would only be able to store positive values (not equal to zero) and infinite or NaN would also not be supported.

The advantage of such a format would be a wider range and/or a higher precision than a float data type with the same number of bits.

  • Related