Skip to content

Commit

Permalink
schubfach: add rounding option
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Jul 1, 2024
1 parent 69732c1 commit ef19b4a
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions code/schubfach/implementation.lisp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
(in-package #:quaviver/schubfach)

(deftype rounding ()
`(member :toward-zero :away-from-zero))

(defclass client (quaviver/trailing-zeros:client)
())
((rounding :accessor rounding
:initarg :rounding
:initform :away-from-zero)))

(defmethod initialize-instance :after ((client client) &rest initargs &key)
(declare (ignore initargs))
(check-type (rounding client) rounding))

(defmacro %schubfach (client value type expt10 round-to-odd)
(with-accessors ((arithmetic-size quaviver:arithmetic-size)
Expand Down Expand Up @@ -65,12 +74,10 @@
k
sign))))
(let* ((mid (+ (ash s 2) 2))
(round-up (>= significand mid)
;; yitzchak: changed this to match
;; Burger-Dybvig rounding
#+(or)(or (> significand mid)
(and (= significand mid)
(logbitp s 0)))))
(round-up (or (> significand mid)
(and (= significand mid)
(or (eq (rounding ,client) :away-from-zero)
(logbitp s 0))))))
(declare (type (unsigned-byte ,word-size)
mid))
(values (if round-up (1+ s) s)
Expand Down

0 comments on commit ef19b4a

Please sign in to comment.