isinf() on NaN args
Steve Kargl
sgk at troutmask.apl.washington.edu
Wed Jun 5 16:38:38 UTC 2013
On Wed, Jun 05, 2013 at 09:05:58AM -0700, David Schultz wrote:
> On Wed, Jun 05, 2013, Bruce Evans wrote:
> > Is isinf(x) (or even fpclassify(x)) permitted to raise FE_INVALID if
> > x is a (quiet) NaN? It shouldn't, but I can't find where C99 requires
> > this. I can only find where C99 requires FE_INVALID to not be raised
> > for comparison macros.
> >
> > It should raise if x is a signaling NaN, but C99 doesn't specify
> > signaling NaNs and the hardware behaviour is more varied and the
> > software bugs are larger for signaling NaNs, so getting this wrong in
> > many cases doesn't matter much.
>
> The equivalent operation in IEEE-754R never raises an exception,
> even for signaling NaNs. If we ignore signaling NaNs for a
> moment, I think the general idea is to raise an invalid exception
> in two situations:
>
> 1. at the moment when a NaN is produced from non-NaN inputs
> (this is similar to the rule that overflow is raised only
> when the overflow first occurs)
>
> 2. for operations that don't return a floating-point result,
> whenever there's no sensible answer to return
>
> The second case covers things like conversion to integer, ilogb,
> and comparison operators. One could argue that classification
> macros like isinf() always have a sensible true or false answer,
> though, because you're asking a question about what kind of value
> you have.
IIRC, C99 defers to IEC 60559 (aka IEEE 754) when a behavior is not
specified within C99. The copy of IEEE 754 that I have states
Some functions, such as the copy operation y := x without change
of format, may at the implementor's option be treated as nonarithmetic
operations which do not signal the invalid operation exception for
signaling NaNs; the functions in question are (1), (2), (6), and (7).
...
(7) Isnan(x), or equivalently x != x, returns the value TRUE if x is
a NaN, and returns FALSE otherwise.
This means that isnan is not required to raised the invalid operation.
--
Steve
More information about the freebsd-numerics
mailing list