From 930c713b762a2e6c1eed2a2a499c5dc97b59057d Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Thu, 25 Dec 2008 21:00:14 -0500 Subject: [PATCH] added missing assertion check for (fxdiv (least-fixnum) -1) and (fxdiv-and-mod (least-fixnum) -1). --- scheme/ikarus.fixnums.ss | 45 +++++++++++++++++++--------------------- scheme/last-revision | 2 +- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/scheme/ikarus.fixnums.ss b/scheme/ikarus.fixnums.ss index cc1ff0d..4ea1328 100644 --- a/scheme/ikarus.fixnums.ss +++ b/scheme/ikarus.fixnums.ss @@ -469,32 +469,29 @@ ($fx+ m0 m) ($fx- m0 m)))))) - (define (fxdiv-and-mod x y) - (if (fixnum? x) - (if (fixnum? y) - (if ($fx= y 0) - (die 'fxdiv-and-mod "division by 0") - ($fxdiv-and-mod x y)) - (die 'fxdiv-and-mod "not a fixnum" y)) - (die 'fxdiv-and-mod "not a fixnum" x))) + (define-syntax define-div-proc + (syntax-rules () + [(_ who $unsafe-op overflow-check?) + (define (who x y) + (if (fixnum? x) + (if (fixnum? y) + (if ($fx> y 0) + ($unsafe-op x y) + (if ($fx= y 0) + (die 'who "division by 0" x y) + (if (and overflow-check? ($fx= y -1)) + (if ($fx= x (least-fixnum)) + (die 'who "result not representable as fixnum" + x y) + ($unsafe-op x y)) + ($unsafe-op x y)))) + (die 'who "not a fixnum" y)) + (die 'who "not a fixnum" x)))])) - (define (fxdiv x y) - (if (fixnum? x) - (if (fixnum? y) - (if ($fx= y 0) - (die 'fxdiv "division by 0") - ($fxdiv x y)) - (die 'fxdiv "not a fixnum" y)) - (die 'fxdiv "not a fixnum" x))) + (define-div-proc fxdiv $fxdiv #t) + (define-div-proc fxmod $fxmod #f) + (define-div-proc fxdiv-and-mod $fxdiv-and-mod #t) - (define (fxmod x y) - (if (fixnum? x) - (if (fixnum? y) - (if ($fx= y 0) - (die 'fxmod "modision by 0") - ($fxmod x y)) - (die 'fxmod "not a fixnum" y)) - (die 'fxmod "not a fixnum" x))) (define ($fxdiv0-and-mod0 n m) (let ([d0 (quotient n m)]) diff --git a/scheme/last-revision b/scheme/last-revision index 1c38c90..921f45a 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1725 +1726