;; Function To Be Tested: RATIONAL ;; ;; Source: Guy L Steele's CLTL ;; Section: 12.6 Type Conversions and Component Extractions on Numbers ;; Page: 214 ;; ;; Created By: Kelly Roach, John Park ;; ;; Creation Date: July 12,1986 ;; ;; Last Update: Jan 28, 1987 - Jim Blum - Substitued (= ...) for (eq.. ...) ;; ;; Filed As: {ERIS}CML>TEST>12-6-RATIONAL.TEST ;; ;; ;; Syntax: (RATIONAL NUMBER) ;; ;; Function Description: ;; Each of these functions converts any non-complex number to be a rational ;; number. If the argument is already rational, it is returned. ;; The two functions differ in their treatment of floating-point numbers. ;; ;; RATIONAL assumes that the floating-point number is completely accurate ;; and returns a rational number mathematically equal to the precise ;; value of the floating-point number. ;; ;; RATIONALIZE assumes that the ;; floating-point number is accurate only to the precision of the ;; floating-point representation, and may return any rational number for ;; which the floating-point number is the best available approximation of ;; its format; in doing this it attempts to keep both numerator and ;; denominator small. ;; ;; It is always the case that ;; ;; (FLOAT (RATIONAL X) X) = X ;; ;; and ;; ;; (FLOAT (RATIONALIZE X) X) = X ;; ;; That is, rationalizing a floating-point number by either method ;; and then converting it back ;; to a floating-point number of the same format produces the original number. ;; What distinguishes the two functions is that RATIONAL typically ;; has a simple, inexpensive implementation, whereas RATIONALIZE goes ;; to more trouble to produce a result that is more pleasant to view and ;; simpler for some purposes to compute with. ;; ;; Argument(s): NUMBER - a number ;; ;; Returns: a number ;; (do-test rational-test (and (= (rational 10) 10) (= (float (rational 3.1)) (/ 31 10)) (rationalp (rational 3.1)) (= (float (rational 3.1)) 3.1) (= (float (rational (/ 3 10))) (/ 3 10)) (rationalp (rational (/ 3 10))) (= (rational 3E3) 3000))) STOP