aurum_numeric/
num.rs

1// Copyright (c) 2016-2017 <daggerbot@gmail.com>
2// This software is available under the terms of the zlib license.
3// See COPYING.md for more information.
4
5/// Get the additive identity of a numeric type.
6pub trait Zero {
7    fn zero () -> Self;
8}
9
10/// Get the multiplicative identity for a numeric type.
11pub trait One {
12    fn one () -> Self;
13}
14
15macro_rules! impl_zero_one_int {
16    ($($ty:ty),*) => { $(
17        impl Zero for $ty {
18            fn zero () -> $ty { 0 }
19        }
20
21        impl One for $ty {
22            fn one() -> $ty { 1 }
23        }
24    )* };
25}
26
27macro_rules! impl_zero_one_float {
28    ($($ty:ty),*) => { $(
29        impl Zero for $ty {
30            fn zero () -> $ty { 0.0 }
31        }
32
33        impl One for $ty {
34            fn one () -> $ty { 1.0 }
35        }
36    )* };
37}
38
39impl_zero_one_int!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
40impl_zero_one_float!(f32, f64);