[Cfp-interest 2330] Re: infinity and exceptions

Vincent Lefevre vincent at vinc17.net
Sat Jan 15 03:34:19 PST 2022


On 2022-01-14 16:37:44 -0800, Jim Thomas wrote:
> > On Jan 14, 2022, at 3:42 AM, Vincent Lefevre <vincent at vinc17.net> wrote:
> > 
> > On 2022-01-13 21:06:35 -0800, Fred J. Tydeman wrote:
> >> On Fri, 14 Jan 2022 14:22:00 +1100 (AEDT) Damian McGuckin wrote:
> >>> 
> >>> On Thu, 13 Jan 2022, Fred J. Tydeman wrote:
> >>>> How about adding to 5.2.4.2.2 #16 and #17:
> >>>> 16: The evaluation of INFINITY does not raise any FP exceptions.
> >>>> 17: The evaluation of NAN does not raise any FP exceptions.
> > 
> > OK for me.
> > 
> >>> Yes. But then again, how do you evaluate NAN?
> > 
> > Just like any expression.
> 
> I don’t see where C mentions evaluating a macro. Might need to say
> something like “The evaluation of the expanded macro does not raise
> floating-point exceptions.

Maybe. But when one writes a macro name, it can be either the name
itself, the expression formed by the name of the macro (where the
macro will be expanded), or the value (obtained through the evaluation
of the expansion of the macro), depending on the context. I think that
the context is quite clear here, because the only thing that can be
evaluated is an expression.

> However, this seems like a new proposal. For the list of things to
> consider for the next revision?

Yes, that would be a change of the standard.

> >> I have been sent the output of a program that did
> >>  float f;
> >>  f = NAN;
> >> and the raised overflow, inexact, and invalid.
> >> My guess:  It appears that NAN was defined as (INFINITY * 0.f)
> >> and INFINITY was defined as (LDBL_MAX * LDBL_MAX)
> > 
> > Indeed, that's incorrect, concerning the exceptions, but also
> > the values when rounding toward zero could be used (one would
> > get LDBL_MAX for INFINITY and 0 for NAN), and the types too.

Actually, FP exceptions are not disallowed by the current standard,
as it just says that INFINITY and NAN expand to constant expressions,
and FP exceptions may occur in a constant expression (when evaluated
at run time).

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list