ebi_arithmetic/fraction/
fraction.rs

1//======================== set type alias based on compile flags ========================//
2
3#[cfg(any(
4    all(
5        not(feature = "exactarithmetic"),
6        not(feature = "approximatearithmetic")
7    ),
8    all(feature = "exactarithmetic", feature = "approximatearithmetic")
9))]
10pub type Fraction = super::fraction_enum::FractionEnum;
11
12#[cfg(all(not(feature = "exactarithmetic"), feature = "approximatearithmetic"))]
13pub type Fraction = super::fraction_f64::FractionF64;
14
15#[cfg(all(feature = "exactarithmetic", not(feature = "approximatearithmetic")))]
16pub type Fraction = super::fraction_exact::FractionExact;
17
18//======================== fraction tools ========================//
19
20pub const APPROX_DIGITS: u64 = 5;
21pub const EPSILON: f64 = 1e-13;
22
23#[macro_export]
24/// Convenience short-hand macro to create fractions.
25macro_rules! f {
26    ($e: expr) => {
27        Fraction::from($e)
28    };
29
30    ($e: expr, $f: expr) => {
31        Fraction::from(($e, $f))
32    };
33}
34pub use f;
35
36#[macro_export]
37/// Convenience short-hand macro to create a fraction representing zero.
38macro_rules! f0 {
39    () => {
40        Fraction::zero()
41    };
42}
43pub use f0;
44
45#[macro_export]
46/// Convenience short-hand macro to create a fraction representing one.
47macro_rules! f1 {
48    () => {
49        Fraction::one()
50    };
51}
52pub use f1;