toFraction
Returns a simple fraction representing the value.
Summary
Use it when decimal values need to be shown or stored as rational numbers.
AI Contract
Signature
Parameters
Returns
Returns [numerator, denominator], both as Arith instances.
Behavior
- Without a maximum denominator, returns the exact fraction with the smallest necessary denominator.
- With a maximum denominator, returns the closest fraction whose denominator does not exceed the limit.
- For non-finite values, returns a non-finite numerator and denominator zero.
Examples
Errors
- Throws if
maxDenominatoris not a positive integer orInfinity. - Throws if
maxDenominatoris invalid whileSTRICTistrue.
Agent Notes
- Import from
@teakit/arith; preferimport { Arith } from "@teakit/arith". - Use
new Arith(...)to construct values. Do not generateArith(...)as a function call. - Use string inputs for exact decimal values, especially money-like values.
- Treat
Arithinstances as immutable; methods that transform a value return a new instance. - Do not mutate internal fields such as
c,e,s, or_isArith.