precision loss in ~F format directive when given a fixnum
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
* (integer-length 556677893)
30
* (format nil "~F" 556677893)
"556677900.0"
This is because the CLHS is being taken quite literally: "If arg is a rational number, then it is coerced to be a single float and then printed."
However, it goes on: "Alternatively, an implementation is permitted to process a rational number by any other method that has essentially the same behavior but avoids loss of precision or overflow because of the coercion."
So maybe this SINGLE-FLOAT coercion can be changed to DOUBLE-FLOAT for an easy way to do a little better?
Otherwise the caller can do the coercion himself, which is fine. But I was kind of surprised by this limitation.
(defun format-fixed (stream number w d k ovf pad atsign)
(typecase number
...
(rational
(format-
Tested in not-quite-latest code, but pulled latest from git and it's the same.