Exact rational number arithmetic, homed on the Rational class.
Literal syntax: 1/3, -2/7. The generic operators dispatch rational
operands through the type ops; / promotes inexact int division.
rationalmake-rationalrat-denomrat-first-denomrat-numerrat-signrat-addrat-subrat-mulrat-divrat-ltrat-modrat-eqrat?ensure-ratrational-type/Divide numbers; integer division produces rationals when not exact.
Parameters:
NUMBER — Numbers to divideReturns: NUMBER — Quotient
Examples:
(/ 6 3) => 2
(/ 1 3) => 1/3
(/ 3) => 1/3Rational(Rational type)The rational type handle, for Convert and Type.
Returns: ATOM — The RATIONAL type handle
(Rational make n d)Make the rational n/d in lowest terms; a whole result is the integer it equals.
Parameters:
INTEGER — NumeratorINTEGER — Denominator, not zeroReturns: RATIONAL|INTEGER — n/d reduced
(Rational rational? x)Test whether a value is a rational number or integer.
Parameters:
ANY — Value to testReturns: BOOL — True if x is rational or integer
(Rational exact? x)Test whether a value is an exact number.
Parameters:
ANY — Value to testReturns: BOOL — True if x is exact (rational or integer)
(Rational numerator x)Return the numerator of a rational number.
Parameters:
RATIONAL|INTEGER — Rational or integerReturns: INTEGER — Numerator of the rational, or the integer itself
(Rational denominator x)Return the denominator of a rational number.
Parameters:
RATIONAL|INTEGER — Rational or integerReturns: INTEGER — Denominator of the rational, or 1 for integers
(Rational + a b)Add two rationals (ints promote).
Parameters:
RATIONAL|INTEGER — First operandRATIONAL|INTEGER — Second operandReturns: RATIONAL|INTEGER — Sum, reduced to lowest terms
(Rational - a b)Subtract two rationals (ints promote).
Parameters:
RATIONAL|INTEGER — First operandRATIONAL|INTEGER — Second operandReturns: RATIONAL|INTEGER — Difference, reduced to lowest terms
(Rational * a b)Multiply two rationals (ints promote).
Parameters:
RATIONAL|INTEGER — First operandRATIONAL|INTEGER — Second operandReturns: RATIONAL|INTEGER — Product, reduced to lowest terms
(Rational / a b)Divide two rationals (ints promote).
Parameters:
RATIONAL|INTEGER — DividendRATIONAL|INTEGER — DivisorReturns: RATIONAL|INTEGER — Quotient, reduced to lowest terms
(Rational < a b)Test whether a is less than b (ints promote).
Parameters:
RATIONAL|INTEGER — Left operandRATIONAL|INTEGER — Right operandReturns: BOOL — True if a < b
(Rational = a b)Test whether a equals b (ints promote).
Parameters:
RATIONAL|INTEGER — Left operandRATIONAL|INTEGER — Right operandReturns: BOOL — True if a equals b
number?Test whether a value is any numeric type (now including rationals).
Parameters:
ANY — Value to testReturns: BOOL — True if x is a number
Examples:
(number? 1/2) => #t