Placeholders for integer division

This commit is contained in:
Justin Ethier 2016-01-28 22:38:46 -05:00
parent a0211b229a
commit 7747ca9da2

View file

@ -15,6 +15,14 @@
odd?
gcd
lcm
quotient
remainder
truncate-quotient
truncate-remainder
truncate/
floor-quotient
floor-remainder
floor/
call-with-current-continuation
call/cc
call-with-values
@ -885,7 +893,6 @@
make_int(result, i % j);
return_closcall1(data, k, &result);
}")
(define floor-remainder modulo)
(define (odd? num) (= (modulo num 2) 1))
(define (even? num) (= (modulo num 2) 0))
(define (exact-integer? num)
@ -929,4 +936,24 @@
1
(foldl lcm/main (car nums) (cdr nums))))
;; END gcd lcm
;; TODO: neither of these two are correct, they are just placeholders
(define quotient /)
(define remainder modulo)
(define truncate-quotient quotient)
(define truncate-remainder remainder)
(define (truncate/ n m)
(values (truncate-quotient n m) (truncate-remainder n m)))
(define (floor-quotient n m)
(let ((res (floor (/ n m))))
(if (and (exact? n) (exact? m))
(exact res)
res)))
;(define floor-remainder modulo)
(define (floor-remainder n m)
(- n (* m (floor-quotient n m))))
(define (floor/ n m)
(values (floor-quotient n m) (floor-remainder n m)))
))