From: Taylor R Campbell Date: Fri, 30 Nov 2018 06:48:05 +0000 (+0000) Subject: Define and expose flo:precision. X-Git-Tag: mit-scheme-pucked-10.1.7~3^2~95 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=4110934060a92803966e70b39c2ee6e25bb25d08;p=mit-scheme.git Define and expose flo:precision. This is the same as flo:significand-digits-base-2, but its name doesn't imply base 2 -- it refers to whatever the floating-point radix is. Not that we're likely to do decimal floating-point ever, but maybe you might want to write code that could be used in another environment that does. --- diff --git a/src/relnotes/flonum b/src/relnotes/flonum index cd953f323..e42ef8fb6 100644 --- a/src/relnotes/flonum +++ b/src/relnotes/flonum @@ -4,7 +4,10 @@ New flonum-related definitions: always 2 but useful for assertions if you want to future-proof code that assumes it with a noisy failure in case we ever violate the assumption. -- flo:radix. - Floating-point radix as a flonum. +. flo:radix. - Floating-point radix as a flonum. +. flo:precision - Number of digits in a significand, including the hidden + one bit for normal binary floating-point numbers. For binary64 + floating-point, this is 53. . flo:error-bound - Greatest possible relative error in rounding to nearest. . flo:log-error-bound = (log flo:error-bound) . flo:ulp-of-one - Distance from 1 to next greater floating-point number. diff --git a/src/runtime/arith.scm b/src/runtime/arith.scm index 87e25a1cd..ae273999f 100644 --- a/src/runtime/arith.scm +++ b/src/runtime/arith.scm @@ -95,6 +95,7 @@ USA. (define-integrable flo:radix 2) (define-integrable flo:radix. 2.) +(define flo:precision) (define flo:ulp-of-one) (define flo:error-bound) (define flo:log-error-bound) @@ -119,6 +120,7 @@ USA. (define (initialize-microcode-dependencies!) (let ((p microcode-id/floating-mantissa-bits)) + (set! flo:precision p) (set! flo:significand-digits-base-2 p) ;; Add two here because first and last digits may be ;; "partial" in the sense that each represents less than the diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 5777e63ef..71c552823 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -3403,6 +3403,7 @@ USA. flo:log-error-bound flo:normal-exponent-max flo:normal-exponent-min + flo:precision flo:radix flo:radix. flo:significand-digits-base-10 diff --git a/tests/runtime/test-arith.scm b/tests/runtime/test-arith.scm index acfee8048..0de60324a 100644 --- a/tests/runtime/test-arith.scm +++ b/tests/runtime/test-arith.scm @@ -943,7 +943,6 @@ USA. (- z)))))) (assert (= flo:radix 2)) -(define flo:precision flo:significand-digits-base-2) (define-enumerated-test 'exact->inexact `((,(+ 1 (expt flo:radix flo:precision))