Home > Software design >  Are floatN_t in stdfloat Guaranteed to be IEEE-Compliant?
Are floatN_t in stdfloat Guaranteed to be IEEE-Compliant?

Time:01-24

Unlike fundamental types – float, double and long double – are the new floatN_t types in <stdfloat> introduced in C 23 going to be always IEEE standard binary floating point types?

The cppreference page for fixed width floating-point does mention the bits of precision and exponent, which matches with IEEE standards. But that page doesn't explicitly mentions about IEEE standards anywhere. IEEE compliant floating points means, they not only should have same bits of precision and exponent, but the standard also lists many operations which have to be supported in a standard compliant way. So do these types strictly follow that?

CodePudding user response:

Yes. The relevant section from the latest Draft for the C 23 Standard (cited below) makes explicit mention of the ISO/IEC/IEEE 60559 floating-point standard for the float*_t types. That is identical to the IEE-754 standard according to Wikipedia:

The international standard ISO/IEC/IEEE 60559:2011 (with content identical to IEEE 754-2008) has been approved for adoption through ISO/IEC JTC 1/SC 25 under the ISO/IEEE PSDO Agreement and published.

Here is the first part of the relevant section from the Draft C 23 Standard (the definitions for other 'precision' types are similar):

6.8.3 Optional extended floating-point types    [basic.extended.fp]
1    If the implementation supports an extended floating-point type ([basic.fundamental]) whose properties are specified by the ISO/IEC/IEEE 60559 floating-point interchange format binary16, then the typedef-name std​::​float16_­t is defined in the header <stdfloat> and names such a type, the macro __STDCPP_­FLOAT16_­T__ is defined ([cpp.predefined]), and the floating-point literal suffixes f16 and F16 are supported ([lex.fcon]).

(… And similarly for float32_t, float64_t, etc.)

Note: In terms of whether the cited paragraph demands that operations on such a type conform to the IEEE/ISO Standard, I would argue that it does. The "properties" of such variables includes their behaviour, and not just their representation format.

CodePudding user response:

Yes, they are.

[stdfloat.syn] states that

The header defines type aliases for the optional extended floating-point types that are specified in [basic.extended.fp].

In turn, [basic.extended.fp] references types which are specified by ISO/IEC/IEEE 60559 floating-point interchange format

ISO/IEC/IEEE 60559 is the newer version of 754

  • Related