Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Feb 2007 18:02:04 GMT
From:      Denis Koreshkov<dynamic-wind@mail.ru>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/109692: printing -NaN
Message-ID:  <200702281802.l1SI24Cb005332@www.freebsd.org>
Resent-Message-ID: <200702281810.l1SIA3Mm035400@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         109692
>Category:       bin
>Synopsis:       printing -NaN
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Feb 28 18:10:03 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Denis Koreshkov
>Release:        freebsd 6.2-stable
>Organization:
BMSTU
>Environment:
>Description:

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.
>How-To-Repeat:

printf("%g %g\n", +0.0/0.0, -0.0/0.0);

outputs: NaN NaN
which should be: NaN -NaN

>Fix:

vfprintf(3) tests for a 'double' argument being an Inf or a NaN using isinf() and isinf().
Then, an Inf's signum is detected by a trivial arithmetic comparison to 0.0
But arithmetic comparisons fail when an argument is a NaN, so there is no corresponding code to set a negative NaN's signum  to '-'.

Consider using copysign(1.0, _double) which returns +1.0 and -1.0 for +NaN and -NaN. This is the case for the msun libm used in FreeBSD, though other implementations of copysign(3) may not derive a NaN's signum correctly, or raise an exception with signaling NaNs.
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200702281802.l1SI24Cb005332>