summaryrefslogtreecommitdiffstats
path: root/ratize.scm
diff options
context:
space:
mode:
authorJames LewisMoss <dres@debian.org>2001-07-27 23:45:29 -0400
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:29 -0800
commitf559c149c83da84d0b1c285f0298c84aec564af9 (patch)
treef1c91bcb9bb5e6dad87b643127c3f878d80d89ee /ratize.scm
parentc394920caedf3dac1981bb6b10eeb47fd6e4bb21 (diff)
parent87b82b5822ca54228cfa6df29be3ad9d4bc47d16 (diff)
downloadslib-f559c149c83da84d0b1c285f0298c84aec564af9.tar.gz
slib-f559c149c83da84d0b1c285f0298c84aec564af9.zip
Import Debian changes 2d2-1debian/2d2-1
slib (2d2-1) unstable; urgency=low * New upstream version * Revert back to free. Is now so. slib (2d1-1) unstable; urgency=low * New upstream version. * Move to non-free. FSF pointed out license doesn't allow modified versions to be distributed. * Get a complete list of copyrights that apply to the source into copyright file. * Remove setup for guile 1.3. * Remove postrm. Just calling install-info (lintian) Move install-info call to prerm since doc-base doesn't do install-info. slib (2c9-3) unstable; urgency=low * Change info location to section "The Algorithmic Language Scheme" to match up with where guile puts it's files. * Postinst is running slibconfig now. (Closes: #75891) slib (2c9-2) unstable; urgency=low * Stop installing slibconfig (for guile). * In postinst if /usr/sbin/slibconnfig exists call it (Close: #75843 #75891). slib (2c9-1) unstable; urgency=low * New upstream (Closes: #74760) * replace string-index with strsrch:string-index in http-cgi.scm. * Add doc-base support (Closes: #31163)
Diffstat (limited to 'ratize.scm')
-rw-r--r--ratize.scm26
1 files changed, 15 insertions, 11 deletions
diff --git a/ratize.scm b/ratize.scm
index d8cad11..9737934 100644
--- a/ratize.scm
+++ b/ratize.scm
@@ -1,13 +1,17 @@
-;;;; "ratize.scm" Convert number to rational number
+;;;; "ratize.scm" Find simplest number ratios
-(define (rational:simplest x y)
- (define (sr x y) (let ((fx (floor x)) (fy (floor y)))
- (cond ((not (< fx x)) fx)
- ((= fx fy) (+ fx (/ (sr (/ (- y fy)) (/ (- x fx))))))
- (else (+ 1 fx)))))
- (cond ((< y x) (rational:simplest y x))
- ((not (< x y)) (if (rational? x) x (slib:error)))
+(define (find-ratio-between x y)
+ (define (sr x y)
+ (let ((fx (inexact->exact (floor x))) (fy (inexact->exact (floor y))))
+ (cond ((>= fx x) (list fx 1))
+ ((= fx fy) (let ((rat (sr (/ (- y fy)) (/ (- x fx)))))
+ (list (+ (cadr rat) (* fx (car rat))) (car rat))))
+ (else (list (+ 1 fx) 1)))))
+ (cond ((< y x) (find-ratio-between y x))
+ ((>= x y) (list x 1))
((positive? x) (sr x y))
- ((negative? y) (- (sr (- y) (- x))))
- (else (if (and (exact? x) (exact? y)) 0 0.0))))
-(define (rationalize x e) (rational:simplest (- x e) (+ x e)))
+ ((negative? y) (let ((rat (sr (- y) (- x))))
+ (list (- (car rat)) (cadr rat))))
+ (else '(0 1))))
+(define (find-ratio x e) (find-ratio-between (- x e) (+ x e)))
+(define (rationalize x e) (apply / (find-ratio x e)))