From dd5967c4333e1c06770133839387541ba72f994c Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Sat, 19 Jan 2008 15:33:52 -0500 Subject: [PATCH] Added special cases for fixnum args to div and mod. --- scheme/ikarus.numerics.ss | 36 ++++++++++++++++++++++++++++++++---- scheme/last-revision | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/scheme/ikarus.numerics.ss b/scheme/ikarus.numerics.ss index e232011..7914a38 100644 --- a/scheme/ikarus.numerics.ss +++ b/scheme/ikarus.numerics.ss @@ -2741,11 +2741,39 @@ (div-and-mod* n m 'div-and-mod)) (define (div n m) - (let-values ([(a b) (div-and-mod* n m 'div)]) - a)) + (import (ikarus system $fx)) + (cond + [(and (fixnum? n) (fixnum? m)) + (cond + [(eq? m 0) (error 'div "division by 0")] + [else + (let ([d0 ($fxquotient n m)]) + (if ($fx>= n ($fx* d0 m)) + d0 + (if ($fx>= m 0) + ($fx- d0 1) + ($fx+ d0 1))))])] + [else + (let-values ([(a b) (div-and-mod* n m 'div)]) + a)])) + (define (mod n m) - (let-values ([(a b) (div-and-mod* n m 'mod)]) - b)) + (import (ikarus system $fx)) + (cond + [(and (fixnum? n) (fixnum? m)) + (cond + [(eq? m 0) (error 'mod "division by 0")] + [else + (let ([d0 ($fxquotient n m)]) + (let ([m0 ($fx- n ($fx* d0 m))]) + (if ($fx>= m0 0) + m0 + (if ($fx>= m 0) + ($fx+ m0 m) + ($fx- m0 m)))))])] + [else + (let-values ([(a b) (div-and-mod* n m 'mod)]) + b)])) (define (div0-and-mod0 x y) (define who 'div0-and-mod0) diff --git a/scheme/last-revision b/scheme/last-revision index cd692fa..e714efc 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1346 +1347