~ chicken-core (chicken-5) 9d8ceff12b43a6e559d8592e0e6bd72fc44185c7
commit 9d8ceff12b43a6e559d8592e0e6bd72fc44185c7 Author: felix <felix@call-with-current-continuation.org> AuthorDate: Thu Sep 2 04:27:14 2010 -0400 Commit: felix <felix@call-with-current-continuation.org> CommitDate: Thu Sep 2 04:27:14 2010 -0400 simplifed modulo diff --git a/library.scm b/library.scm index b1566295..dc3cde45 100644 --- a/library.scm +++ b/library.scm @@ -957,18 +957,11 @@ EOF (define remainder (lambda (x y) (- x (* (quotient x y) y))) ) -(define modulo - (let ([floor floor]) - (lambda (x y) - (let ((div (/ x y))) - (- x (* (if (integer? div) - div - (let* ([fd (floor div)] - [fdx (##core#inline "C_quickflonumtruncate" fd)] ) - (if (= fd fdx) - fdx - fd) ) ) - y) ) ) ) ) ) +(define (modulo a b) ; copied from chibi scheme without asking Alex + (let ((res (- a (* (quotient a b) b))) ) ; remainder + (if (< b 0) + (if (<= res 0) res (+ res b)) + (if (>= res 0) res (+ res b))))) (define (even? n) (##core#inline "C_i_evenp" n)) (define (odd? n) (##core#inline "C_i_oddp" n))Trap