Skip to main content

Crate oxinum_rational

Crate oxinum_rational 

Source
Expand description

Exact rational arithmetic for the OxiNum ecosystem.

Provides RBig and Relaxed re-exports from dashu-ratio, plus additional functions: continued fraction expansion, best rational approximation, decimal string conversion, mediant, mixed number representation, and floor/ceil/round/truncate operations.

Modules§

native
Native arbitrary-precision rational implementation built on oxinum_int::native::BigInt / oxinum_int::native::BigUint.

Structs§

IBig
An signed arbitrary precision integer.
MixedNumber
Newtype wrapper providing FromStr for the mixed-number format.
RBig
An arbitrary precision rational number.
Relaxed
An arbitrary precision rational number without strict reduction.
UBig
An unsigned arbitrary precision integer.

Enums§

OxiNumError
Errors from OxiNum operations.

Functions§

best_rational_approximation
Find the best rational approximation to x with denominator at most max_denom.
continued_fraction
Compute the continued fraction expansion of a rational number.
farey_sequence
Generate the order-n Farey sequence F_n.
from_continued_fraction
Reconstruct a rational number from its continued fraction coefficients.
from_f32
Convert an f32 to an exact rational.
from_f64
Convert an f64 to an exact rational.
from_stern_brocot_path
Reconstruct a positive rational from its Stern-Brocot path.
mediant
Compute the mediant of two rationals: (a_num + b_num) / (a_den + b_den).
mixed_number
Decompose a rational into a mixed number: (whole, fractional) where whole is the integer part (toward zero) and fractional is the remaining proper fraction with the same sign.
parse_mixed
Parse a mixed-number string.
rational_abs
Returns the absolute value of x.
rational_ceil
Returns the smallest integer not less than x (toward positive infinity).
rational_floor
Returns the largest integer not greater than x (toward negative infinity).
rational_from_integer
Construct an RBig from an integer value.
rational_is_integer
Returns true iff x represents an integer (i.e. its reduced denominator is one).
rational_pow
Raise a rational to an integer power.
rational_reciprocal
Returns the reciprocal 1/x.
rational_round
Returns the nearest integer to x (ties away from zero).
rational_signum
Returns the sign of x: -1, 0, or +1 as an IBig.
rational_to_integer
Extract the integer value of x if it is one.
rational_truncate
Returns the integer part of x (truncated toward zero).
stern_brocot_path
Compute the Stern-Brocot path encoding for a positive rational.
to_decimal_string
Convert a rational to a decimal string with decimal_places digits after the point (truncated, not rounded).
to_f64
Convert a rational to the nearest f64 (round-to-nearest, ties-to-even).
to_f64_exact
Convert a rational to an f64, requiring exact representability.

Type Aliases§

BigRational
Type alias for clarity.
OxiNumResult
Convenience alias for Result<T, OxiNumError>.