Functional Weave
Code in Rust

math.rational@2.0.0

impl/python/rational_to_integer.py

496 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  ← rational, another function of this group · built into the same file, even by a slim install
from .math_rational_types import Rational
from .math_round_div import RoundingMode, round_div  ← from math.round-div ^1.0.0 · built alongside by fune


def rational_to_integer(r: Rational, mode: RoundingMode) -> int:
    """The integer a fraction rounds to, under an explicit rounding mode.

    This is the point where an exact rate becomes minor units, so the policy
    is the caller's to state.
    """
    n = rational(r.numerator, r.denominator)
    return round_div(n.numerator, n.denominator, mode)