C++ Logo

std-discussion

Advanced search

[expr.arith.conv] and FP16 <=> int

From: Marc Mutz <marc.mutz_at_[hidden]>
Date: Thu, 14 Dec 2023 17:39:28 +0100
Hi,

Was is ever discussed that the present wording in
https://eel.is/c++draft/expr.arith.conv#1.3.2 (introduced, AFAICT, by
wg21.link/p1467), in combination with
https://eel.is/c++draft/expr.spaceship#4, means that

      1'000'000 <=> numeric_limits<std::float16_t>::infinity()

is _not_ `less`, but `equivalent` (this behaviour, of course, is the
same for the non-spaceship relational operators by way of
https://eel.is/c++draft/expr.rel#3).

That's because the wording requires that this be evaluated as

    std::float16_t(1'000'000) <=> numeric_limits<std::float16_t>::infinity()

and std::float16_t(1'000'000) _is_ infinity().

This wording isn't a problem for _standard_ floating-point types,
because converting any integral type (except maybe int128) to float
yield a finite value.

For <=>, the fix could be as easy as changing
https://eel.is/c++draft/expr.spaceship#4.1 to

    ... to a _standard_ floating-point type ...

but [expr.rel] is more complicated.

First, let's determine whether others think this is a problem, too.

Thanks,
Marc

Received on 2023-12-14 16:39:32