C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] [isocpp-ext] Report from the recent C/C++ liaison meeting (SG22); includes new floating point types(!)

From: David Olsen <dolsen_at_[hidden]>
Date: Sun, 19 Sep 2021 02:11:29 +0000
Fred Tydeman wrote:
>> How about places where 'float' promotes to 'double' and '_Float32' does not promote? Such as printf()?

Good point. Thanks. The proposed rules for floating-point promotion are the same in both languages, where float is the only thing that ever promotes to double. So the difference in usual arithmetic conversions means that:
        printf("%g", (float)1.0 + (_Float32)2.0);
is undefined behavior in C (because the expression has type _Float32, which does not promote), but
        printf("%g", (float)1.0 + (std::float32_t)2.0);
is well-formed in C++ (because the expression has type float, which does promote).

I see this as an argument for C to change the rules so that
        float + _Float32 -> float
Not a compelling argument by itself, but a point in favor of the change.


-----Original Message-----
From: Fred J. Tydeman <tydeman_at_[hidden]>
Sent: Saturday, September 18, 2021 1:26 PM
To: ext_at_[hidden]; liaison_at_[hidden]
Cc: C++ Library Evolution Working Group <lib-ext_at_[hidden]>; David Olsen <dolsen_at_[hidden]>; Joseph Myers <joseph_at_[hidden]>; Matthias Kretz <m.kretz_at_[hidden]>; SG6 numerics <sci_at_[hidden]>; WG14/WG21 liaison mailing list <liaison_at_[hidden]>
Subject: Re: [wg14/wg21 liaison] [isocpp-ext] Report from the recent C/C++ liaison meeting (SG22); includes new floating point types(!)

On Sat, 18 Sep 2021 20:36:40 +0000 David Olsen via Liaison wrote:
>
>Matthias Kretz pointed out that the proposed rules for C and C++ have different arithmetic conversion rules:
>>> float + _Float32 -> _Float32
>>> float + std::float32 -> float.
>
>As Jens said, "Not good." It's also unfortunate that I didn't notice this difference sooner. But before I start to panic about this, I want to understand what the impact of this difference is.
>
>When float and _Float32 have the same representation and sets of values, can well-formed C code detect the difference between "float + _Float32 -> _Float32" and "float + _Float32 -> float" without using a _Generic expression? Are there situations where the result type of "float + _Float32" affects the correctness of the program or the behavior of a correct program? It would be very easy to detect this in C++. I can't think of how to detect the difference in C without resorting to _Generic, though I don't know C as well.
>
>If the user writes code that is valid in both C and C++ (assuming that the user has dealt with the fact that _Float32 and std::float32_t are different names for essentially the same type in the two languages), will the fact that "float + _Float32/std::float32_t" have different result types in the two languages cause any differences in behavior?
>

How about places where 'float' promotes to 'double' and '_Float32' does not promote?
Such as printf()?


---
Fred J. Tydeman        Tydeman Consulting
tydeman_at_[hidden]      Testing, numerics, programming
+1 (702) 608-6093      Vice-chair of PL22.11 (ANSI "C")
Savers sleep well, investors eat well, spenders work forever.

Received on 2021-09-18 21:11:35