4

With the introduction of the new fixed-width floating point types in C++23 (the std::floatN_t types in <stdfloat>), some guarantees regarding the representation of floating-point types are not yet totally clear to me.

My reading from the latest draft (6.8.3) suggests the following:

  1. float and double are never guaranteed to be IEC-60553 binary floating-point types, even if std::float32_t and std::float64_t exist;

  2. _FloatN types (from C23) are not guaranteed to exist, even though it is "recommended practice" (6.8.3.7).

(A comment on 2.: Even if _FloatN types do exist -- following the recommended practice --, this still does not assert that float and double are IEC-60553 binary floating-point types. There is no indication of that. For contrast, in ISO C23, if _Float32 and _Float64 exist, then float and double are guaranteed to be IEC-60553 binary floating-point types with the same representation respectively, yet distinct types; see C23 F.2.1.1 and H.2.2.3-4.)

The cppreference page on this matter suggests 2. is wrong, but I don't have the final published standard document to check.

Therefore, which one of the above assertions (1. or 2.) are correct, and which ones are incorrect?

5
  • I believe your reading is correct. Only C23 makes any sort of guarantees on the exact representation of float and double, if the relevant macros are defined. I think cppreference is just simplifying for the common case. BTW: For a real-world example of a platform that would be compatible with C++23 but not the optional C23 feature, look at Arduino UNO and its 4 byte double Commented May 30 at 23:04
  • 2
    My interpretation is that the introduction of the new types doesn't affect the existing types, these are unchanged. Just like the existence of char8_t doesn't necessarily affect the encoding of plain char. Commented May 31 at 0:08
  • Isn't std::numeric_limits<>::is_iec559 created to know if a type is IEC-60559 / IEEE-754, precisely? Commented Jun 2 at 11:45
  • @Wisblade Yes, but this is not what the question is asking. Moreover, numeric_limits is not usable in the preprocessor. Commented Jun 5 at 19:32
  • @alecov Preprocessor wasn't even mentioned in your question, but numeric_limits is compatible with constexpr and static_assert - which will break compilation if these types aren't compatible with what you need. It also allow to safely define an using clause to define an alternative type to ensure IEC-60559 compatibility... Standard doesn't guarantee this compatibility, but provides a way to check it. What else do you need? Standard is clear, IEC-60559 isn't always available, same for fixed-point float. Both assertions are correct, even if very few compilers will lack these features. Commented Jun 5 at 21:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.