1use num_traits;
12
13pub trait Zero {
14 fn zero() -> Self;
15}
16
17impl<T: num_traits::Zero> Zero for T {
18 fn zero() -> T {
19 num_traits::Zero::zero()
20 }
21}
22
23pub trait One {
24 fn one() -> Self;
25}
26
27impl<T: num_traits::One> One for T {
28 fn one() -> T {
29 num_traits::One::one()
30 }
31}
32
33pub trait Round: Copy {
34 fn round(self) -> Self;
35}
36pub trait Floor: Copy {
37 fn floor(self) -> Self;
38}
39pub trait Ceil: Copy {
40 fn ceil(self) -> Self;
41}
42
43macro_rules! num_int {
44 ($ty:ty) => (
45 impl Round for $ty {
46 #[inline]
47 fn round(self) -> $ty { self }
48 }
49 impl Floor for $ty {
50 #[inline]
51 fn floor(self) -> $ty { self }
52 }
53 impl Ceil for $ty {
54 #[inline]
55 fn ceil(self) -> $ty { self }
56 }
57 )
58}
59macro_rules! num_float {
60 ($ty:ty) => (
61 impl Round for $ty {
62 #[inline]
63 fn round(self) -> $ty { self.round() }
64 }
65 impl Floor for $ty {
66 #[inline]
67 fn floor(self) -> $ty { self.floor() }
68 }
69 impl Ceil for $ty {
70 #[inline]
71 fn ceil(self) -> $ty { self.ceil() }
72 }
73 )
74}
75
76num_int!(i16);
77num_int!(u16);
78num_int!(i32);
79num_int!(u32);
80num_int!(i64);
81num_int!(u64);
82num_int!(isize);
83num_int!(usize);
84num_float!(f32);
85num_float!(f64);