[armedbear-devel] bug in format ~f
Carlos Ungil
carlos.ungil at gmail.com
Sun Mar 31 11:14:50 UTC 2013
Hello,
comparing output from different implementations I've found the following
(minor) bug:
> (format t "~,2f" 0.999)
1.0 ;; should be 1.00
I think there is a problem here as well:
> (format t "~5f" 0.00000001)
.0000 ;; should print " 0.0"
Only SBCL gives the output I would expect, most implementations print
".0000" as ABCL does. From the HyperSpec 22.3.3.1: "If the parameter d is
omitted, then there is no constraint on the number of digits to appear
after the decimal point. A value is chosen for d in such a way that as many
digits as possible may be printed subject to the width constraint imposed
by the parameter w and the constraint that ___no trailing zero digits may
appear in the fraction, except that if the fraction to be printed is zero,
then a single zero digit should appear after the decimal point___ if
permitted by the width constraint." This problem appears only when the
value is close to zero, otherwise the output is fine:
> (format t "~5f" 1.00000001)
1.0 ;; OK
I guess those zero digits are not considered trailing because there is no
non-zero digit before but I think the specification still requires the
fraction to be printed with a single zero digit after the decimal point.
Regards,
Carlos Ungil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/armedbear-devel/attachments/20130331/a7d653af/attachment.html>
More information about the armedbear-devel
mailing list