From: Taylor R Campbell Date: Sun, 28 Oct 2018 19:56:35 +0000 (+0000) Subject: Eliminate flo:epsilon. X-Git-Tag: mit-scheme-pucked-10.1.2~16^2~136 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=27ef2fabaf72e6febe1bc9113c9a4aa7a4b719b6;p=mit-scheme.git Eliminate flo:epsilon. The name is confusing. It means two different things: the distance from 1 to the next positive floating-point number, and the maximum relative error of rounding to the nearest floating-point number. Provide the separate names flo:ulp-of-one and flo:error-bound for these so that you're not even tempted to be confused by the name `epsilon'. (But continue to say `eps' in the proofs in the comments where it's obvious that we're talking about relative error bounds and a short name for that is essential for legibility.) --- diff --git a/src/runtime/arith.scm b/src/runtime/arith.scm index 019ad736d..a119912ca 100644 --- a/src/runtime/arith.scm +++ b/src/runtime/arith.scm @@ -94,8 +94,9 @@ USA. (define rec:pi (flo:* 2. rec:pi/2)) (define flo:radix 2) -(define flo:epsilon) -(define flo:log-epsilon) +(define flo:ulp-of-one) +(define flo:error-bound) +(define flo:log-error-bound) (define flo:normal-exponent-max-base-2) (define flo:normal-exponent-min-base-2) (define flo:normal-exponent-max-base-e) @@ -123,8 +124,9 @@ USA. (flo:/ (int:->flonum p) (flo:/ (flo:log 10.) (flo:log 2.)))))) (set! int:flonum-integer-limit (int:expt 2 p))) - (set! flo:epsilon microcode-id/floating-epsilon) - (set! flo:log-epsilon (flo:log flo:epsilon)) + (set! flo:ulp-of-one microcode-id/floating-epsilon) + (set! flo:error-bound (flo:/ flo:ulp-of-one 2)) + (set! flo:log-error-bound (flo:log flo:error-bound)) (set! flo:normal-exponent-max-base-2 microcode-id/floating-exponent-max) (set! flo:normal-exponent-min-base-2 microcode-id/floating-exponent-min) (set! flo:subnormal-exponent-min-base-2 @@ -2029,7 +2031,7 @@ USA. (define (log1pexp x) (guarantee-real x 'log1pexp) (cond ((<= x flo:subnormal-exponent-min-base-e) 0.) - ((<= x flo:log-epsilon) (exp x)) + ((<= x flo:log-error-bound) (exp x)) ((<= x 18) (log1p (exp x))) ((<= x 33.3) (+ x (exp (- x)))) (else (exact->inexact x)))) @@ -2117,7 +2119,7 @@ USA. ;; e^x/(1 + e^x) < e^x < smallest positive float. (XXX Should ;; raise inexact and underflow here.) 0.) - ((<= x flo:log-epsilon) + ((<= x flo:log-error-bound) ;; e^x < eps, so ;; ;; |e^x - e^x/(1 + e^x)|/|e^x/(1 + e^x)| @@ -2128,7 +2130,7 @@ USA. ;; < eps. ;; (exp x)) - ((<= x (- flo:log-epsilon)) + ((<= x (- flo:log-error-bound)) ;; e^{-x} > 0, so 1 + e^{-x} > 1, and 0 < 1/(1 + e^{-x}) < 1; ;; further, since e^{-x} < 1 + e^{-x}, we also have 0 < ;; e^{-x}/(1 + e^{-x}) < 1. Thus, if exp has relative error @@ -2374,7 +2376,7 @@ USA. (define (logit-exp t) (guarantee-real t 'logit-exp) - (cond ((<= t flo:log-epsilon) + (cond ((<= t flo:log-error-bound) ;; e^t < eps, so since log(e^t/(1 - e^t)) = t - log(1 - e^t), ;; and |log(1 - e^t)| < 1 < |t|, we have ;; diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 6eea6fe64..75032dd44 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -3356,8 +3356,8 @@ USA. cube exact-nonnegative-integer? exact-positive-integer? - flo:epsilon - flo:log-epsilon + flo:error-bound + flo:log-error-bound flo:normal-exponent-max-base-10 flo:normal-exponent-max-base-2 flo:normal-exponent-max-base-e @@ -3370,6 +3370,7 @@ USA. flo:subnormal-exponent-min-base-10 flo:subnormal-exponent-min-base-2 flo:subnormal-exponent-min-base-e + flo:ulp-of-one flonum-printer:engineering-output flonum-printer:normal-output flonum-printer:scientific-output