From: Chris Hanson Date: Wed, 18 Jan 2017 06:01:41 +0000 (-0800) Subject: Move fixnum-limit code into fixart and rename for consistency. X-Git-Tag: mit-scheme-pucked-9.2.12~227^2~108 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=7c3a9e518c0bb845005c057a3256c799273370b6;p=mit-scheme.git Move fixnum-limit code into fixart and rename for consistency. --- diff --git a/src/runtime/arith.scm b/src/runtime/arith.scm index 56b65ac96..5603e4933 100644 --- a/src/runtime/arith.scm +++ b/src/runtime/arith.scm @@ -96,8 +96,6 @@ USA. (define flo:significand-digits-base-2) (define flo:significand-digits-base-10) (define int:flonum-integer-limit) -(define fix:largest-value) -(define fix:smallest-value) (define (initialize-microcode-dependencies!) (let ((p microcode-id/floating-mantissa-bits)) @@ -115,12 +113,6 @@ USA. (set! int:flonum-integer-limit (int:expt 2 p))) unspecific) -(define (largest-fixnum) - fix:largest-value) - -(define (smallest-fixnum) - fix:smallest-value) - (define (initialize-package!) (initialize-microcode-dependencies!) (add-event-receiver! event:after-restore initialize-microcode-dependencies!) @@ -254,21 +246,6 @@ USA. (max/min max complex:max) (max/min min complex:min)) - (let loop ((n 1)) - (if (fix:fixnum? n) - (loop (* n 2)) - (let ((n (- n 1))) - (if (not (fix:fixnum? n)) - (error "Unable to compute largest fixnum:" n)) - (set! fix:largest-value n)))) - (let loop ((n -1)) - (if (fix:fixnum? n) - (loop (* n 2)) - (let ((n (quotient n 2))) - (if (not (fix:fixnum? n)) - (error "Unable to compute smallest fixnum:" n)) - (set! fix:smallest-value n)))) - unspecific) (define (int:max n m) diff --git a/src/runtime/fixart.scm b/src/runtime/fixart.scm index 42ab3206f..75d183650 100644 --- a/src/runtime/fixart.scm +++ b/src/runtime/fixart.scm @@ -78,7 +78,7 @@ USA. (define-guarantee negative-fixnum "negative fixnum") (define-guarantee non-positive-fixnum "non-positive fixnum") (define-guarantee non-negative-fixnum "non-negative fixnum") - + (define (guarantee-index-fixnum object #!optional caller) (if (not (index-fixnum? object)) (error:wrong-type-argument object "index integer" caller))) @@ -92,6 +92,32 @@ USA. (define (fix:>= n m) (not (fix:< n m))) (define (fix:min n m) (if (fix:< n m) n m)) (define (fix:max n m) (if (fix:> n m) n m)) + +(define (fix:largest-value) + (force largest-fixnum-promise)) + +(define largest-fixnum-promise + (delay + (let loop ((n 1)) + (if (fix:fixnum? n) + (loop (* n 2)) + (let ((n (- n 1))) + (if (not (fix:fixnum? n)) + (error "Unable to compute largest fixnum:" n)) + n))))) + +(define (fix:smallest-value) + (force smallest-fixnum-promise)) + +(define smallest-fixnum-promise + (delay + (let loop ((n -1)) + (if (fix:fixnum? n) + (loop (* n 2)) + (let ((n (quotient n 2))) + (if (not (fix:fixnum? n)) + (error "Unable to compute smallest fixnum:" n)) + n))))) ;;;; Flonums diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index aabf22103..54d65d483 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -186,6 +186,8 @@ USA. (parent (runtime)) (export () ;; BEGIN deprecated bindings + (largest-fixnum fix:largest-value) + (smallest-fixnum fix:smallest-value) guarantee-fixnum guarantee-index-fixnum guarantee-limited-index-fixnum @@ -211,6 +213,7 @@ USA. fix:divide fix:fixnum? fix:gcd + fix:largest-value fix:lsh fix:max fix:min @@ -220,6 +223,7 @@ USA. fix:positive? fix:quotient fix:remainder + fix:smallest-value fix:xor fix:zero? fixnum? @@ -3291,7 +3295,6 @@ USA. inexact? integer-divide-quotient integer-divide-remainder - largest-fixnum lcm max min @@ -3303,7 +3306,6 @@ USA. param:flonum-unparser-cutoff quotient remainder - smallest-fixnum square) (initialization (begin diff --git a/src/runtime/stream.scm b/src/runtime/stream.scm index e436af828..2b592cf39 100644 --- a/src/runtime/stream.scm +++ b/src/runtime/stream.scm @@ -279,7 +279,7 @@ USA. (letrec ((primes (cons-stream 3 (fixnum-filter 5))) (fixnum-filter - (let ((limit (fix:- (largest-fixnum) 2))) + (let ((limit (fix:- (fix:largest-value) 2))) (lambda (n) (if (fix:<= n limit) (let loop ((ps primes))