rationalize -- r7rs Definition procedure;
rationalize (from vonuvoli);Procedure variants:
((real-not-inf-not-nan real-positive-or-zero-not-inf) -> (rational))
real-not-inf-not-nan;real-positive-or-zero-not-inf;rational;scheme:base -- (scheme base);scheme -- (scheme);(rationalize x y)The
rationalizeprocedure returns the simplest rational number differing fromxby no more thany. A rational numberr_1is simpler (simplest rational) than another rational numberr_2ifr_1 = p_1/q_1andr_2 = p_2/q_2(in lowest terms) and|p_1| <= |p_2|and|q_1| <= |q_2|. Thus3/5is simpler than4/7. Although not all rationals are comparable in this ordering (consider2/7and3/5), any interval contains a rational number that is simpler than every other rational number in that interval (the simpler2/5lies between2/7and3/5). Note that0 = 0/1is the simplest rational of all.(rationalize (exact .3) 1/10) ===> 1/3 ; exact (rationalize .3 1/10) ===> #i1/3 ; inexact
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.