Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Part IV — Rational

An exact fraction of two arbitrary-precision integers. Nothing is ever rounded: a third is a third, and a third times three is one.

Rational is not in the prelude, which carries the four types most programs reach for. Import it by name, as itself or under the short name Frac:

from decimo import Frac, Rational
from decimo.bigint.bigint import BigInt

The value is always in lowest terms with a positive denominator, so two equal values have the same two parts and == is a comparison of integers rather than of fractions.