This shows you the differences between two versions of the page.

cl:functions:rational [2019/09/14 05:00] |
cl:functions:rational [2019/09/22 06:00] (current) |
||
---|---|---|---|

Line 1: | Line 1: | ||

+ | ====== Function RATIONAL, RATIONALIZE ====== | ||

+ | |||

+ | ====Syntax==== | ||

+ | * **rational ** //number// → //rational// **rationalize** //number// → //rational// | ||

+ | |||

+ | ====Arguments and Values==== | ||

+ | * //number// - a //[[CL:Glossary:real]]//. | ||

+ | * //rational// - a //[[CL:Glossary:rational]]//. | ||

+ | |||

+ | ====Description==== | ||

+ | **rational** and **rationalize** convert //[[CL:Glossary:reals]]// to //[[CL:Glossary:rationals]]//. | ||

+ | |||

+ | If //number// is already //[[CL:Glossary:rational]]//, it is returned. | ||

+ | |||

+ | If //number// is a //[[CL:Glossary:float]]//, **rational** returns a //[[CL:Glossary:rational]]// that is mathematically equal in value to the //[[CL:Glossary:float]]//. **rationalize** returns a //[[CL:Glossary:rational]]// that approximates the //[[CL:Glossary:float]]// to the accuracy of the underlying floating-point representation. | ||

+ | |||

+ | **rational** assumes that the //[[CL:Glossary:float]]// is completely accurate. | ||

+ | |||

+ | **rationalize** assumes that the //[[CL:Glossary:float]]// is accurate only to the precision of the floating-point representation. | ||

+ | |||

+ | ====Examples==== | ||

+ | <blockquote> | ||

+ | (rational 0) <r>0 </r> | ||

+ | (rationalize -11/100) <r>-11/100 </r> | ||

+ | (rational .1) <r>13421773/134217728 ;implementation-dependent </r> | ||

+ | (rationalize .1) <r>1/10</r> | ||

+ | </blockquote> | ||

+ | |||

+ | ====Side Effects==== | ||

+ | None. | ||

+ | |||

+ | ====Affected By==== | ||

+ | The //[[CL:Glossary:implementation]]//. | ||

+ | |||

+ | ====Exceptional Situations==== | ||

+ | Should signal an error of type type-error if //number// is not a //[[CL:Glossary:real]]//. Might signal **[[CL:Types:arithmetic-error]]**. | ||

+ | |||

+ | ====See Also==== | ||

+ | None. | ||

+ | |||

+ | ====Notes==== | ||

+ | Rationalizing a //[[CL:Glossary:float]]// by either method and then converting it back to a //[[CL:Glossary:float]]// of the same format produces the original //number//. | ||

+ | |||

+ | <blockquote> | ||

+ | (float (rational //x//) //x//) | ||

+ | ≡ (float (rationalize //x//) //x//) | ||

+ | ≡ //x// | ||

+ | </blockquote> | ||

+ | |||

+ | \issue{REAL-NUMBER-TYPE:X3J13-MAR-89} | ||