C++ Logo

std-discussion

Advanced search

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

From: Marc Mutz <marc.mutz_at_[hidden]>
Date: Thu, 14 Dec 2023 20:58:56 +0100
On 14.12.23 18:57, Thiago Macieira via Std-Discussion wrote:
> On Thursday, 14 December 2023 13:39:28 -03 Marc Mutz via Std-Discussion wrote:
>> 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()
> This is intentional and thus, by definition, not a problem.
I didn't see any discussion about this in P1467, but I didn't check the
meeting minutes, yet. So I don't see where you take the information from
that it's intentional.
> Did you find an implementation problem resulting in less instead of equivalent?
>

You lost me there, sorry.

If the question is whether I found a problem in practice, then yes.
Apart from the fact that it's a mathematically nonsensical, novel
behaviour, there's also implementation divergence in the same compiler.
GCC casts to float for comparison when the target doesn't support FP16
in hardware, and casts the int to a PF16 if it does.

You might call that a bug in GCC, and it very well might be, but it
might also be that the standard is faulty here.

Thus this thread.

Thanks,
Marc

Received on 2023-12-14 19:59:00