[−][src]Type Definition fraction::prelude::DynaFraction
type DynaFraction<T> = GenericFraction<DynaInt<T, BigUint>>;
Stack allocated, but dynamically growing into heap if necessary
Fraction using T as the base type for numerator and denominator
Whenever possible keeps data in T, but on math overflows
automatically casts values into BigUint, which allocates memory on heap.
Allows to use fractions without memory allocations wherever possible. For unexpectedly big values performs on heap and doesn't suffer from stack overflows. Automatically uses T if an operation on two BigUint numbers produces the result that may fit within T.
Examples
use fraction::{DynaFraction, BigUint}; type D = DynaFraction<u32>; let max_u32 = u32::max_value(); let one = D::from (1u32); let mut val = D::from (max_u32); assert_eq!( // check we still use u32 for the numerator max_u32, val.numer().unwrap().clone().unpack().ok().unwrap() ); val += &one; assert_eq!( // BigUint allocated for the result instead of stack overflow on u32 BigUint::from(max_u32) + BigUint::from(1u8), val.numer().unwrap().clone().unpack().err().unwrap() ); val -= one; assert_eq!( // check we use u32 again max_u32, val.numer().unwrap().clone().unpack().ok().unwrap() );