'Can floats not suport negative or even 0?

It's follow-up question to: How to detect non IEEE-754 float, and how to use them?

In theory, can we assume that c float always support negative numbers?



Solution 1:[1]

Can floats not suport negative or even 0?

I don't think the intention is to allow not supporting negative or zero:

ISO/IEC9899:2017

Characteristics of floating types <float.h>

... The following parameters are used to define the model for each floating-point type:

  • s sign (±1)
  • b base or radix of exponent representation (an integer > 1)
  • e exponent (an integer between a minimum emin and a maximum emax)
  • p precision (the number of base-b digits in the significand)
  • fk nonnegative integers less than b (the significand digits)

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

Solution 2:[2]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eerorika
Solution 2 Martin Rosenau