1pub trait Abs {
5 fn abs(self) -> Self;
7}
8
9pub trait One {
11 fn one() -> Self;
13}
14
15pub trait Zero {
17 fn zero() -> Self;
19}
20
21macro_rules! impl_one {
22 ($one:literal $($ty:ty)+) => ($(
23 impl One for $ty {
24 #[inline]
25 fn one() -> $ty {
26 $one
27 }
28 }
29 )+)
30}
31
32macro_rules! impl_zero {
33 ($zero:literal $($ty:ty)+) => ($(
34 impl Zero for $ty {
35 #[inline]
36 fn zero() -> $ty {
37 $zero
38 }
39 }
40 )+)
41}
42
43macro_rules! impl_abs {
44 ($($ty:ident)+) => ($(
45 impl Abs for $ty {
46 #[inline]
47 fn abs(self) -> $ty {
48 $ty::abs(self)
49 }
50 }
51 )+)
52}
53
54macro_rules! impl_abs_self {
55 ($($ty:ident)+) => ($(
56 impl Abs for $ty {
57 #[inline]
58 fn abs(self) -> $ty {
59 self
60 }
61 }
62 )+)
63}
64
65impl_one! { true bool }
66impl_one! { 1 usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
67impl_one! { 1.0 f32 f64 }
68
69impl_zero! { false bool }
70impl_zero! { 0 usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
71impl_zero! { 0.0 f32 f64 }
72
73impl_abs_self! { usize u8 u16 u32 u64 u128 }
74impl_abs! { isize i8 i16 i32 i64 i128 }
75#[cfg(feature = "std")]
76impl_abs! { f32 f64 }