On Fri, Sep 02, 2011 at 08:39:11PM +0100, Christophe Rhodes wrote:
> Peter Keller <psilord@...> writes:
> no, sorry, that line should still be there but return "shifted" instead
> of "(1+ shifted)". So: if the fractional bits are bigger than 0.5; then
> use (1+ shifted); if they're smaller than 0.5, use shifted; if they are
> exactly 0.5 then if the shifted value is odd, use (1+ shifted) otherwise
> use shifted. Proper round-to-even logic, not at all confusing.
So it turns out your fix isn't quite right:
Linux > sbcl
This is SBCL 22.214.171.124-6113d10, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
;; This works
* (round (* 10.004939019999991d0 1e8))
;; this works too.
* (round 100000000000000.6d0)
;; uh oh!
* (round 100000000000000.6)
debugger invoked on a TYPE-ERROR in thread #<THREAD "initial thread" RUNNING
The value NIL is not of type INTEGER.
Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.
When the 100000000000000.6 value is read as a single-float, round messes up
and thinks it isn't an integer. Same thing happens with (round 1.e14) and