C++ Logo


Advanced search

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

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Fri, 17 Sep 2021 20:19:27 +0200
On 17/09/2021 20.03, Jorg Brown via Ext wrote:
> Already a huge problem is support for "long double": is it 128-bit or 80-bit or 64-bit? I can programmatically detect which of them a given type is, but I can't conditionally #include 128-bit support code unless there's a macro for that purpose, because "#if sizeof(double) == sizeof(long double)" doesn't compile.

<float.h> will tell you everything you need to know,
in macro form.

> Something that would make me incredibly happy is if c++23 said that I could overload on std::float16, std::float32, std::float64, std::float80, and std::float128, and that the basic functions (+-*/, abs, frexp, ldexp) all work on those types, regardless of what the CPU natively supports.

Do you expect software emulation for floating-point arithmetic that the hardware doesn't support?

Alternatively, if there were macros I could check that would tell me if each of these had support - but it would still have to be guaranteed that "float", "long", and "long double" could be passed to my overload, without compile error.

> #ifdef __cpp_float128
> void Handle(std::float128_t f);
> #endif

WG14 N2601 <float.h> provides plenty of macros that are defined
if and only if _FloatN exists to base your #ifdef on.

> = - = - = - =
> Looking at the actual details of http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1312.pdf <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1312.pdf> , I find one thing new and intriguing: "Type-generic macros". Specifically, it says that if you include <tgmath.h>, you can write "pow(2, 3.0)" and get the double version of pow, and you can write "pow(2, 3.0DD)" and get the _Decimal64 version. This is of course common practice in C++, but how does C do this without overloads?

Type-generic macros are not new to C23; they've been around since C99.

> Notably, the most glaring need for this is printf. If they are going to introduce a pow that does the right thing, how about a type-generic "tgprintf", that would automatically convert "%d" and "%u" to "%lld" and "%z" if the type of the parameters being passed were "long long" and "size_t"? (I'm hoping that the compiler would do this transformation, rather than some complicated runtime scheme)

That question is probably best taken up with WG14 directly.


Received on 2021-09-17 13:19:36