Search code examples
cfloating-pointlanguage-lawyerstandards

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

  • 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