C++ Logo

std-discussion

Advanced search

Re: Out-of-range floating-point conversion behavior

From: Hyman Rosen <hyrosen_at_[hidden]>
Date: Fri, 7 Jun 2019 13:57:38 -0400
On Fri, Jun 7, 2019 at 11:49 AM Thiago Macieira via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> CPUs/fpUs can trap that and deliver as an exception, causing the
> program to terminate, instead of delivering ±Inf. That's definitely UB.
>

But that's not what optimizationalists have done with UB. A program that
either terminates or delivers infinity is different from a program where the
compiler can use a proven division by zero to silently elide any code paths
that must lead to it. In the former case, either the program will work as
the
programmer expects or it will crash on the recalcitrant platforms. In the
latter case, the compiler will silently destroy the intent of the programmer
and produce programs with wrong behavior that might not be detected for
years.

Received on 2019-06-07 12:59:37