mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
renaming centered/ balanced/
This commit is contained in:
parent
4193742fe5
commit
975dc690a1
2 changed files with 8 additions and 27 deletions
|
@ -17,25 +17,10 @@
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
;; The builtin quotient and remainder implement truncation - the
|
|
||||||
;; fractional part is always discarded.
|
|
||||||
|
|
||||||
(define truncate-quotient quotient)
|
|
||||||
(define truncate-remainder remainder)
|
|
||||||
(define (truncate/ n m)
|
|
||||||
(values (truncate-quotient n m) (truncate-remainder n m)))
|
|
||||||
|
|
||||||
;; Floor, ceiling and round just compose their corresponding function
|
;; Floor, ceiling and round just compose their corresponding function
|
||||||
;; with division to determine the quotient, and compute the remainder
|
;; with division to determine the quotient, and compute the remainder
|
||||||
;; from that.
|
;; from that.
|
||||||
|
|
||||||
(define (floor-quotient n m)
|
|
||||||
(copy-exactness2 n m (floor (/ n m))))
|
|
||||||
(define (floor-remainder n m)
|
|
||||||
(- n (* m (floor-quotient n m))))
|
|
||||||
(define (floor/ n m)
|
|
||||||
(values (floor-quotient n m) (floor-remainder n m)))
|
|
||||||
|
|
||||||
(define (ceiling-quotient n m)
|
(define (ceiling-quotient n m)
|
||||||
(copy-exactness2 n m (ceiling (/ n m))))
|
(copy-exactness2 n m (ceiling (/ n m))))
|
||||||
(define (ceiling-remainder n m)
|
(define (ceiling-remainder n m)
|
||||||
|
@ -60,16 +45,16 @@
|
||||||
(define (euclidean/ n m)
|
(define (euclidean/ n m)
|
||||||
(values (euclidean-quotient n m) (euclidean-remainder n m)))
|
(values (euclidean-quotient n m) (euclidean-remainder n m)))
|
||||||
|
|
||||||
;; Centered places the remainder in the half-open interval
|
;; Balanced places the remainder in the half-open interval
|
||||||
;; [-m/2, m/2).
|
;; [-m/2, m/2).
|
||||||
|
|
||||||
(define (centered-remainder n m)
|
(define (balanced-remainder n m)
|
||||||
(let ((r (euclidean-remainder n m))
|
(let ((r (euclidean-remainder n m))
|
||||||
(m/2 (abs (/ m 2))))
|
(m/2 (abs (/ m 2))))
|
||||||
(cond ((< r (- m/2)) (+ r (abs m)))
|
(cond ((< r (- m/2)) (+ r (abs m)))
|
||||||
((>= r m/2) (- r (abs m)))
|
((>= r m/2) (- r (abs m)))
|
||||||
(else r))))
|
(else r))))
|
||||||
(define (centered-quotient n m)
|
(define (balanced-quotient n m)
|
||||||
(quotient (- n (centered-remainder n m)) m))
|
(quotient (- n (balanced-remainder n m)) m))
|
||||||
(define (centered/ n m)
|
(define (balanced/ n m)
|
||||||
(values (centered-quotient n m) (centered-remainder n m)))
|
(values (balanced-quotient n m) (balanced-remainder n m)))
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
;; This library is deprecated, occurring in early R7RS drafts before
|
|
||||||
;; being removed.
|
|
||||||
|
|
||||||
(define-library (scheme division)
|
(define-library (scheme division)
|
||||||
(import (chibi))
|
(import (scheme base))
|
||||||
(export ceiling-quotient ceiling-remainder ceiling/
|
(export ceiling-quotient ceiling-remainder ceiling/
|
||||||
centered-quotient centered-remainder centered/
|
|
||||||
euclidean-quotient euclidean-remainder euclidean/
|
euclidean-quotient euclidean-remainder euclidean/
|
||||||
floor-quotient floor-remainder floor/
|
|
||||||
round-quotient round-remainder round/
|
round-quotient round-remainder round/
|
||||||
truncate-quotient truncate-remainder truncate/)
|
balanced-quotient balanced-remainder balanced/)
|
||||||
;; The second definition is always valid, but the first is simpler
|
;; The second definition is always valid, but the first is simpler
|
||||||
;; and faster if exact ratios are supported and handled correctly
|
;; and faster if exact ratios are supported and handled correctly
|
||||||
;; but floor/ceil/round.
|
;; but floor/ceil/round.
|
||||||
|
|
Loading…
Add table
Reference in a new issue