Macro div_int

Source
div_int!() { /* proc-macro */ }
Expand description

A compile-time constructor for DivInt literals.

There are two ways to invoke this macro:

  • div_int!(N / D) constructs a DivInt with numerator N and denominator D.
  • div_int!(N * D) constructs a DivInt with denominator D and the overall value of N.

ยงExamples

use div_int::{div_int, DivInt};

// Numerator type inferred from context.
assert_eq!(div_int!(15 / 30), DivInt::<u8, 30>::from_numerator(15));

// Denominator inferred from context.
assert_eq!(div_int!(15 / _), DivInt::<u8, 30>::from_numerator(15));

// Explicit numerator type.
assert_eq!(div_int!(15u16 / 30), DivInt::<u16, 30>::from_numerator(15));

// Represent the given fraction.
assert_eq!(div_int!(1.5 * 30), DivInt::<u16, 30>::from_numerator(45));
assert_eq!(f64::from(div_int!(1.5u8 * 30)), 1.5f64);

// Represent the given fraction with a specific numerator type.
assert_eq!(div_int!(1.5u64 * 30), DivInt::<u64, 30>::from_numerator(45));