mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-17 01:37:34 +02:00
Progress on integer division
This commit is contained in:
parent
1cf5b78cb3
commit
c2db08de46
1 changed files with 9 additions and 8 deletions
|
@ -138,8 +138,6 @@
|
||||||
; ;error-object-message
|
; ;error-object-message
|
||||||
; ;error-object?
|
; ;error-object?
|
||||||
; ;file-error?
|
; ;file-error?
|
||||||
; ;floor-quotient
|
|
||||||
; ;floor/
|
|
||||||
; ;guard
|
; ;guard
|
||||||
; ;import
|
; ;import
|
||||||
; ;include-ci
|
; ;include-ci
|
||||||
|
@ -155,9 +153,6 @@
|
||||||
; ;read-u8
|
; ;read-u8
|
||||||
; ;symbol=?
|
; ;symbol=?
|
||||||
; ;syntax-rules
|
; ;syntax-rules
|
||||||
; ;truncate-quotient
|
|
||||||
; ;truncate-remainder
|
|
||||||
; ;truncate/
|
|
||||||
; ;u8-ready?
|
; ;u8-ready?
|
||||||
; ;unquote
|
; ;unquote
|
||||||
; ;unquote-splicing
|
; ;unquote-splicing
|
||||||
|
@ -874,7 +869,8 @@
|
||||||
make_double(d, fabs(((double_type *)num)->value));
|
make_double(d, fabs(((double_type *)num)->value));
|
||||||
return_closcall1(data, k, &d);
|
return_closcall1(data, k, &d);
|
||||||
} ")
|
} ")
|
||||||
(define-c modulo
|
;; Apparently C % is actually the remainder, not modulus
|
||||||
|
(define-c remainder
|
||||||
"(void *data, int argc, closure _, object k, object num1, object num2)"
|
"(void *data, int argc, closure _, object k, object num1, object num2)"
|
||||||
" int i, j;
|
" int i, j;
|
||||||
Cyc_check_num(data, num1);
|
Cyc_check_num(data, num1);
|
||||||
|
@ -893,6 +889,12 @@
|
||||||
make_int(result, i % j);
|
make_int(result, i % j);
|
||||||
return_closcall1(data, k, &result);
|
return_closcall1(data, k, &result);
|
||||||
}")
|
}")
|
||||||
|
;; From chibi scheme. Cannot use C % operator
|
||||||
|
(define (modulo a b)
|
||||||
|
(let ((res (remainder a b)))
|
||||||
|
(if (< b 0)
|
||||||
|
(if (<= res 0) res (+ res b))
|
||||||
|
(if (>= res 0) res (+ res b)))))
|
||||||
(define (odd? num) (= (modulo num 2) 1))
|
(define (odd? num) (= (modulo num 2) 1))
|
||||||
(define (even? num) (= (modulo num 2) 0))
|
(define (even? num) (= (modulo num 2) 0))
|
||||||
(define (exact-integer? num)
|
(define (exact-integer? num)
|
||||||
|
@ -937,9 +939,8 @@
|
||||||
(foldl lcm/main (car nums) (cdr nums))))
|
(foldl lcm/main (car nums) (cdr nums))))
|
||||||
;; END gcd lcm
|
;; END gcd lcm
|
||||||
|
|
||||||
;; TODO: neither of these two are correct, they are just placeholders
|
;; TODO: possibly not correct, just a placeholder
|
||||||
(define quotient /)
|
(define quotient /)
|
||||||
(define remainder modulo)
|
|
||||||
|
|
||||||
(define truncate-quotient quotient)
|
(define truncate-quotient quotient)
|
||||||
(define truncate-remainder remainder)
|
(define truncate-remainder remainder)
|
||||||
|
|
Loading…
Add table
Reference in a new issue