From owner-freebsd-bugs@FreeBSD.ORG Thu Jan 10 05:50:03 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0CB5516A419 for ; Thu, 10 Jan 2008 05:50:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E790D13C455 for ; Thu, 10 Jan 2008 05:50:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m0A5o2O3045144 for ; Thu, 10 Jan 2008 05:50:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m0A5o269045143; Thu, 10 Jan 2008 05:50:02 GMT (envelope-from gnats) Date: Thu, 10 Jan 2008 05:50:02 GMT Message-Id: <200801100550.m0A5o269045143@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: David Schultz Cc: Subject: Re: bin/109692: printing -NaN X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: David Schultz List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Jan 2008 05:50:03 -0000 The following reply was made to PR kern/109692; it has been noted by GNATS. From: David Schultz To: Denis Koreshkov Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/109692: printing -NaN Date: Thu, 10 Jan 2008 00:46:37 -0500 On Wed, Feb 28, 2007, Denis Koreshkov wrote: > The vfprintf() function correctly formats +Inf and -Inf but it > has no provision for distinguishing between +NaN and -NaN. Hence > all functions of printf(3) family output all -NaNs as NaNs. Thanks for pointing this out. I believe that this is historical and deliberate behavior, and I do not think it violates C99 or IEEE P754. To quote from IEEE P754: Conversion of a quiet NaN in a supported format to an external character sequence shall produce a language-defined one of "nan" or a sequence that is equivalent except for case (e.g., "NaN"), with an optional preceding sign. The sign of a NaN has no meaning. (5.12.1) In an abstract sense, NaNs aren't signed; none of the usual mathematical operators can be used to distinguish a "positive NaN" from a "negative NaN", even though the underlying representation includes a sign bit. Only operations that operate directly on the bit strings (IEEE P754 defines assignment, negation, fabs, and copysign) have a well-defined effect on the sign bit. For all other operations, the hardware is granted free license to set the sign bit of a NaN however it wants (6.3). Thus, printing the sign for NaNs would probably reduce portability, not to mention violating POLA.