Macro extended_rational::uratio [] [src]

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

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

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

Panics

On attempt to create negative rational. Doesn't panic in optimized builds.

Alternatives

  • uratio!(n, d) is equivalent to ratio!(n, d).try_unsigned()
  • uratio!(n) is equivalent to ratio!(n).try_unsigned()

Examples

let five_thirds = uratio!(5, 3);
let seventeen = uratio!(17);

assert_eq!(five_thirds, URational::new(5, 3));
assert_eq!(seventeen, URational::new(17, 1));