Date: Wed, 5 Jun 2013 09:37:13 -0700 From: Steve Kargl <sgk@troutmask.apl.washington.edu> To: David Schultz <das@CSAIL.MIT.EDU> Cc: numerics@freebsd.org, Bruce Evans <brde@optusnet.com.au> Subject: Re: isinf() on NaN args Message-ID: <20130605163712.GA74110@troutmask.apl.washington.edu> In-Reply-To: <20130605160558.GA44189@zim.MIT.EDU> References: <20130605183354.V1244@besplex.bde.org> <20130605160558.GA44189@zim.MIT.EDU>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130605163712.GA74110>