Wednesday, December 29, 2021

Digest for comp.lang.c++@googlegroups.com - 4 updates in 1 topic

Bonita Montero <Bonita.Montero@gmail.com>: Dec 29 08:00PM +0100

I just wanted to give a set a load-factor of +Inf. So I just wrote
1.0f / 0.0f to prevent numeric_limits<float>::infinity() because
the first is shorter. MSVC took this as an error but clang++ and
clang-cl accepted the code. Which compiler is right ?
Jack Lemmon <invalid@invalid.net>: Dec 29 07:15PM

On 29/12/2021 19:00, Bonita Montero wrote:
> 1.0f / 0.0f to prevent numeric_limits<float>::infinity() because
> the first is shorter. MSVC took this as an error but clang++ and
> clang-cl accepted the code. Which compiler is right ?
 
In mathematics, a number divided by zero is undefined. So I would say
MSVC is correct though it should have simply said <Nan>.
Bonita Montero <Bonita.Montero@gmail.com>: Dec 29 09:20PM +0100

Am 29.12.2021 um 20:15 schrieb Jack Lemmon:
>> clang-cl accepted the code. Which compiler is right ?
 
> In mathematics, a number divided by zero is undefined.
> So I would say MSVC is correct though it should have simply said <Nan>.
 
No, it's infinity. 0.0 / 0.0 is NaN.
"james...@alumni.caltech.edu" <jameskuyper@alumni.caltech.edu>: Dec 29 01:08PM -0800

On Wednesday, December 29, 2021 at 2:00:21 PM UTC-5, Bonita Montero wrote:
> 1.0f / 0.0f to prevent numeric_limits<float>::infinity() because
> the first is shorter. MSVC took this as an error but clang++ and
> clang-cl accepted the code. Which compiler is right ?
 
Both are right. "If the second operand of / or % is zero the behavior
is undefined." (7.6.5p4). When the behavior is undefined, there's
no wrong way to handle it. In particular, it's permitted to implement
ISO/IEC 60559 (== IEEE 754) semantics. I won't be able to check
my copy of that standard until Monday, but off the top of my head,
I think it specifies that division by 0 results in an infinity with the
same sign as the numerator.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: