[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug in floating-point printer -- more specific



Well, actually your fix has two bugs: it doesn't implement round-to-even
(round 2.5) should be 2, not 3.  And it doesn't work right for negative numbers.
(round -2.6) should be -3, not -2.  Also, code/float.lisp should be
portable code, and thus shouldn't be patched on a per-machine basis.

Instead, I suggest the following patch (which I have checked in) to
compiler/sparc/float.lisp:

diff   -r1.4 float.lisp
305a306
>   #-sun4
306a308
>   #-sun4
308a311,321
> #+sun4
> (deftransform %unary-round ((x) (float) (signed-byte 32))
>   '(let* ((trunc (truly-the (signed-byte 32) (%unary-truncate x)))
>         (extra (- x trunc))
>         (absx (abs extra))
>         (one-half (float 1/2 x)))
>      (if (if (oddp trunc)
>            (>= absx one-half)
>            (> absx one-half))
>        (truly-the (signed-byte 32) (%unary-truncate (+ x extra)))
>        trunc)))

  Rob