Issue #519 - Allow truncate-quotient to return fixnums

Return a fixnum when fixnum args are received, per R7RS.
This commit is contained in:
Justin Ethier 2024-01-06 14:37:36 -08:00
parent 1a0f42386b
commit 43923a6e44

View file

@ -1525,21 +1525,17 @@
"(void *data, int argc, closure _, object k, object n)" "(void *data, int argc, closure _, object k, object n)"
" Cyc_get_ratio(data, k, n, 0);") " Cyc_get_ratio(data, k, n, 0);")
;; TODO: integrate into quotient? (define-c fixnum?
(define-c fixnum? "(void *data, int argc, closure _, object k, object obj)"
"(void *data, int argc, closure _, object k, object obj)" " return_closcall1(data, k,
" return_closcall1(data, k, obj_is_int(obj) ? boolean_t : boolean_f); "
obj_is_int(obj) ? boolean_t : boolean_f); ") "(void *data, object ptr, object obj)"
" return obj_is_int(obj) ? boolean_t : boolean_f; ")
(define (quotient x y) (define (quotient x y)
;; TODO: if x and y are fixnums, do fast divide and return a fixnum (if (and (fixnum? x) (fixnum? y))
;; TODO: above good enough or are there special cases?? (exact (truncate (/ x y)))
(truncate (/ x y))) (truncate (/ x y))))
;; TODO: something like this, but do we want inline?
;;(let ((result (/ x y)))
;; (if (and (fixnum? x) (fixnum? y))
;; (exact (truncate result))
;; (truncate result))))
(define truncate-quotient quotient) (define truncate-quotient quotient)
(define truncate-remainder remainder) (define truncate-remainder remainder)