Functional Weave
Code in TypeScript

math.rational@2.0.0

impl/python/compare_rational.py

381 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .math_rational_rational import rational_parts  ← rational, another function of this group · built into the same file, even by a slim install
from .math_rational_types import Rational


def compare_rational(a: Rational, b: Rational) -> int:
    """-1, 0 or 1. Exact: cross-multiplied, never through a float."""
    an, ad = rational_parts(a)
    bn, bd = rational_parts(b)
    left = an * bd
    right = bn * ad
    return -1 if left < right else 1 if left > right else 0