Macro extended_rational::ratio [] [src]

macro_rules! ratio {
    ( $ n : expr , $ d : expr ) => { ... };
    ( $ n : expr ) => { ... };
}

A macro for creating a new signed rational using a given ratio or decimal

Floating-point conversions may be wrong due to small rounding errors.

Alternatives

  • ratio!(n, d) is equivalent to Rational::from([n, d])
  • ratio!(n) is equivalent to Rational::from(n)

Examples

let five_thirds = ratio!(5, 3);
let neg_seven_and_a_half = ratio!(-7.5);

assert_eq!(five_thirds, Rational::from([5, 3]));
assert_eq!(neg_seven_and_a_half, Rational::new(-15, 2));