expression
BigRational exact fractional arithmetic
Represent a ratio of arbitrary-precision integers. A nonzero denominator is required. Addition can preserve fractions that have no finite decimal expansion. Numerators and denominators may grow. Expected stdout (not executed): 1/2 Common mistake: Constructing a rational with zero denominator or assuming fractional arithmetic is cost-free. Dependency: num-bigint =0.4.6; num-rational =0.4.2. See the staged Cargo fixture. Exact-version API and resolution not tested.
Formal Syntax & Structure
rust syntaxrust
BigRational::new(numerator,denominator)Working Example
Example Snippetrust
fn main() { use num_bigint::BigInt; use num_rational::BigRational; let one_third=BigRational::new(BigInt::from(1),BigInt::from(3)); let one_sixth=BigRational::new(BigInt::from(1),BigInt::from(6)); let result=one_third+one_sixth; println!("{}/{}",result.numer(),result.denom());}