ospf_rust_math/algebra/concept/
bounded.rs

1use super::{Arithmetic, Precision};
2
3pub trait Bounded: 'static + Sized {
4    const MINIMUM: &'static Option<Self>;
5    const MAXIMUM: &'static Option<Self>;
6    const POSITIVE_MINIMUM: &'static Self;
7}
8
9impl Bounded for bool {
10    const MINIMUM: &'static Option<bool> = &Some(false);
11    const MAXIMUM: &'static Option<bool> = &Some(true);
12    const POSITIVE_MINIMUM: &'static Self = &true;
13}
14
15macro_rules! int_bound_template {
16    ($($type:ident)*) => ($(
17        impl Bounded for $type {
18            const MINIMUM: &'static Option<Self> = &Some(<$type>::MIN);
19            const MAXIMUM: &'static Option<Self> = &Some(<$type>::MAX);
20            const POSITIVE_MINIMUM: &'static Self = Self::ONE;
21        }
22    )*)
23}
24int_bound_template! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
25
26macro_rules! floating_bound_template {
27    ($($type:ident)*) => ($(
28        impl Bounded for $type {
29            const MINIMUM: &'static Option<Self> = &Some(<$type>::MIN);
30            const MAXIMUM: &'static Option<Self> = &Some(<$type>::MAX);
31            const POSITIVE_MINIMUM: &'static Self = &Self::EPSILON;
32        }
33    )*)
34}
35floating_bound_template! { f32 f64 }