From: Christophe Rhodes <csr21@ca...>  20110902 19:39:20

Peter Keller <psilord@...> writes: > On Fri, Sep 02, 2011 at 07:46:20PM +0100, Christophe Rhodes wrote: >> I'm glad I put the PS in and sent this to Raymond Toy, because he >> pointed out that... >> >> Christophe Rhodes <csr21@...> writes: >> >> > The answer I think is that the notfixnum branch in %unaryround is >> > completely wrong. The logic looks like a weird mix of truncate and >> > roundtoeven, getting I think neither of them right. I think if we >> > replace the ROUNDED binding with >> > (if (minusp exp) >> > (let ((fractionalbits (logand bits (lognot (ash 1 ( exp))))) >> > (0.5bits (ash 1 ( 1 exp)))) >> > (cond >> > ((> fractionalbits 0.5bits) (1+ shifted)) >> > ((< fractionalbits 0.5bits) (1+ shifted)) >> >> ... this line is wrong. "Why increment if the fractional part is less >> that 0.5?" (Why indeed?) > > So I should just remove the < condition code path from the COND clause? 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 roundtoeven logic, not at all confusing. Cheers, Christophe 