home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / RiscPc / programmation / scm4e2.arc / !Scm / slib / ratize < prev    next >
Text File  |  1994-12-07  |  525b  |  14 lines

  1. ;;;; "ratize.scm" Convert number to rational number
  2.  
  3. (define (rational:simplest x y)
  4.   (define (sr x y) (let ((fx (floor x)) (fy (floor y)))
  5.             (cond ((not (< fx x)) fx)
  6.               ((= fx fy) (+ fx (/ (sr (/ (- y fy)) (/ (- x fx))))))
  7.               (else (+ 1 fx)))))
  8.   (cond ((< y x) (rational:simplest y x))
  9.     ((not (< x y)) (if (rational? x) x (slib:error)))
  10.     ((positive? x) (sr x y))
  11.     ((negative? y) (- (sr (- y) (- x))))
  12.     (else (if (and (exact? x) (exact? y)) 0 0.0))))
  13. (define (rationalize x e) (rational:simplest (- x e) (+ x e)))
  14.