Rational numbers
Factor handbook » The language » Numbers

Prev:Integers
Next:Floats


ratio


When we add, subtract or multiply any two integers, the result is always an integer. However, dividing a numerator by a denominator that is not an integral divisor of the denominator yields a ratio:
1210 11 / .
110

100 330 / .
10/33

14 10 / .
1+2/5

Ratios are printed and can be input literally in the form above. Ratios are always reduced to lowest terms by factoring out the greatest common divisor of the numerator and denominator. A ratio with a denominator of 1 becomes an integer. Division with a denominator of 0 throws an error.

Ratios behave just like any other number -- all numerical operations work as you would expect.
1/2 1/3 + .
5/6

100 6 / 3 * .
50

Ratios can be taken apart:
numerator ( a/b -- a )

denominator ( a/b -- b )

>fraction ( a/b -- a b )


See also
Ratio syntax