bin/109692: printing -NaN
Denis Koreshkov
dynamic-wind at mail.ru
Wed Feb 28 18:10:04 UTC 2007
>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:
More information about the freebsd-bugs
mailing list