From ad1c18be22d33d7dbda5344c801ee62c3e069072 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sun, 1 Feb 2004 06:43:21 +0000 Subject: [PATCH] r8583: add naagum's epsilon function --- math.lisp | 23 +++++++++++++++++++++++ package.lisp | 1 + 2 files changed, 24 insertions(+) diff --git a/math.lisp b/math.lisp index e911844..fcbab3c 100644 --- a/math.lisp +++ b/math.lisp @@ -73,3 +73,26 @@ (defun fixnum-width () (nth-value 0 (truncate (+ (/ (log (1+ most-positive-fixnum)) (log 2)) .5)))) + +(defun scaled-epsilon (float &optional (operation '+)) + "Return the smallest number that would return a value different from + FLOAT if OPERATION were applied to FLOAT and this number. OPERATION + should be either + or -, and defauls to +." + (multiple-value-bind (significand exponent) + (decode-float float) + (multiple-value-bind (1.0-significand 1.0-exponent) + (decode-float (float 1.0 float)) + (if (and (eq operation '-) + (= significand 1.0-significand)) + (scale-float (typecase float + (short-float short-float-negative-epsilon) + (single-float single-float-negative-epsilon) + (double-float double-float-negative-epsilon) + (long-float long-float-negative-epsilon)) + (- exponent 1.0-exponent)) + (scale-float (typecase float + (short-float short-float-epsilon) + (single-float single-float-epsilon) + (double-float double-float-epsilon) + (long-float long-float-epsilon)) + (- exponent 1.0-exponent)))))) diff --git a/package.lisp b/package.lisp index 1ba962f..62bf637 100644 --- a/package.lisp +++ b/package.lisp @@ -115,6 +115,7 @@ #:ensure-integer #:histogram #:fixnum-width + #:scaled-epsilon ;; macros.lisp #:time-iterations -- 2.34.1