matrix_oxide/
numbers.rs

1/// Marker trait for categorizing the set of all number types
2/// and enforcing type constraints.
3pub trait Numeric: AsF64 {}
4impl Numeric for i8 {}
5impl Numeric for i16 {}
6impl Numeric for i32 {}
7impl Numeric for i64 {}
8impl Numeric for i128 {}
9impl Numeric for u8 {}
10impl Numeric for u16 {}
11impl Numeric for u32 {}
12impl Numeric for u64 {}
13impl Numeric for u128 {}
14impl Numeric for f32 {}
15impl Numeric for f64 {}
16
17/// Marker trait for categorizing the set of integer
18/// number types and enforcing type constraints.
19pub trait Integers {}
20impl Integers for i8 {}
21impl Integers for i16 {}
22impl Integers for i32 {}
23impl Integers for i64 {}
24impl Integers for i128 {}
25impl Integers for u8 {}
26impl Integers for u16 {}
27impl Integers for u32 {}
28impl Integers for u64 {}
29impl Integers for u128 {}
30
31/// Marker trait for categorizing the set of floating
32/// point number types and enforcing type constraints.
33pub trait Floats {}
34impl Floats for f32 {}
35impl Floats for f64 {}
36
37/// Convert something to f64.
38/// NOTE: This is lossy for big integers.
39pub trait AsF64 {
40    fn as_f64(&self) -> f64;
41}
42/// Convert an i8 to an f64.
43impl AsF64 for i8 {
44    fn as_f64(&self) -> f64 {
45        *self as f64
46    }
47}
48impl AsF64 for i16 {
49    fn as_f64(&self) -> f64 {
50        *self as f64
51    }
52}
53impl AsF64 for i32 {
54    fn as_f64(&self) -> f64 {
55        *self as f64
56    }
57}
58impl AsF64 for i64 {
59    fn as_f64(&self) -> f64 {
60        *self as f64
61    }
62}
63impl AsF64 for i128 {
64    fn as_f64(&self) -> f64 {
65        *self as f64
66    }
67}
68impl AsF64 for u8 {
69    fn as_f64(&self) -> f64 {
70        *self as f64
71    }
72}
73impl AsF64 for u16 {
74    fn as_f64(&self) -> f64 {
75        *self as f64
76    }
77}
78impl AsF64 for u32 {
79    fn as_f64(&self) -> f64 {
80        *self as f64
81    }
82}
83impl AsF64 for u64 {
84    fn as_f64(&self) -> f64 {
85        *self as f64
86    }
87}
88impl AsF64 for u128 {
89    fn as_f64(&self) -> f64 {
90        *self as f64
91    }
92}
93impl AsF64 for f32 {
94    fn as_f64(&self) -> f64 {
95        *self as f64
96    }
97}
98impl AsF64 for f64 {
99    fn as_f64(&self) -> f64 {
100        *self
101    }
102}