From owner-freebsd-numerics@FreeBSD.ORG Wed Jun 5 16:38:38 2013 Return-Path: Delivered-To: numerics@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C1D0BCDA for ; Wed, 5 Jun 2013 16:38:38 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by mx1.freebsd.org (Postfix) with ESMTP id A48D91255 for ; Wed, 5 Jun 2013 16:38:38 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.6/8.14.6) with ESMTP id r55GbDlT074217; Wed, 5 Jun 2013 09:37:13 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.6/8.14.6/Submit) id r55GbDmR074216; Wed, 5 Jun 2013 09:37:13 -0700 (PDT) (envelope-from sgk) Date: Wed, 5 Jun 2013 09:37:13 -0700 From: Steve Kargl To: David Schultz Subject: Re: isinf() on NaN args Message-ID: <20130605163712.GA74110@troutmask.apl.washington.edu> References: <20130605183354.V1244@besplex.bde.org> <20130605160558.GA44189@zim.MIT.EDU> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20130605160558.GA44189@zim.MIT.EDU> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: numerics@freebsd.org, Bruce Evans X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Jun 2013 16:38:38 -0000 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