(truly-the fixnum (%unary-round number))
(multiple-value-bind (bits exp) (integer-decode-float number)
(let* ((shifted (ash bits exp))
- (rounded (if (and (minusp exp)
- (oddp shifted)
- (eql (logand bits
- (lognot (ash -1 (- exp))))
- (ash 1 (- -1 exp))))
- (1+ shifted)
+ (rounded (if (minusp exp)
+ (let ((fractional-bits (logand bits (lognot (ash -1 (- exp)))))
+ (0.5bits (ash 1 (- -1 exp))))
+ (cond
+ ((> fractional-bits 0.5bits) (1+ shifted))
+ ((< fractional-bits 0.5bits) shifted)
+ (t (if (oddp shifted) (1+ shifted) shifted))))
shifted)))
(if (minusp number)
(- rounded)