Changeset 16154
 Timestamp:
 Aug 9, 2014, 11:43:40 PM (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/source/lib/numbers.lisp
r15705 r16154 428 428 429 429 430 # 431 (defun rationalize (x) 432 (etypecase x 433 (rational x) 434 (real 435 (cond ((minusp x) ( (rationalize ( x)))) 436 ((zerop x) 0) 437 (t 438 (let ((eps (etypecase x 439 (singlefloat singlefloatepsilon) 440 (doublefloat doublefloatepsilon))) 441 (y ()) 442 (a ())) 443 (do ((xx x (setq y (/ (float 1.0 x) ( xx (float a x))))) 444 (num (setq a (truncate x)) 445 (+ (* (setq a (truncate y)) num) onum)) 446 (den 1 (+ (* a den) oden)) 447 (onum 1 num) 448 (oden 0 den)) 449 ((and (not (zerop den)) 450 (not (> (abs (/ ( x (/ (float num x) 451 (float den x))) 452 x)) 453 eps))) 454 (integer/integer num den))))))))) 455 # 456 430 457 431 (defun rationalize (number) 458 432 "Converts any REAL to a RATIONAL. Floats are converted to a simple rational
Note: See TracChangeset
for help on using the changeset viewer.