| 8 to refer to the methods with the full path, it is often necesary to use [`ToNalgebraRealField`][crate::nalgebra_support::ToNalgebraRealField] to hide the nalgebra implementations until |
8 to refer to the methods with the full path, it is often necesary to use [`ToNalgebraRealField`][crate::nalgebra_support::ToNalgebraRealField] to hide the nalgebra implementations until |
| 9 absolutely necessary to use nalgebra. |
9 absolutely necessary to use nalgebra. |
| 10 */ |
10 */ |
| 11 |
11 |
| 12 //use trait_set::trait_set; |
12 //use trait_set::trait_set; |
| |
13 pub use num_traits::cast::AsPrimitive; |
| 13 pub use num_traits::Float as NumTraitsFloat; // needed to re-export functions. |
14 pub use num_traits::Float as NumTraitsFloat; // needed to re-export functions. |
| 14 pub use num_traits::cast::AsPrimitive; |
|
| 15 |
15 |
| 16 pub use simba::scalar::{ |
16 pub use simba::scalar::{ |
| 17 ClosedAdd, ClosedAddAssign, |
17 ClosedAdd, ClosedAddAssign, ClosedDiv, ClosedDivAssign, ClosedMul, ClosedMulAssign, ClosedNeg, |
| 18 ClosedSub, ClosedSubAssign, |
18 ClosedSub, ClosedSubAssign, |
| 19 ClosedMul, ClosedMulAssign, |
|
| 20 ClosedDiv, ClosedDivAssign, |
|
| 21 ClosedNeg |
|
| 22 }; |
19 }; |
| 23 |
20 |
| 24 /// Typical integer type |
21 /// Typical integer type |
| 25 #[allow(non_camel_case_types)] |
22 #[allow(non_camel_case_types)] |
| 26 pub type int = i64; |
23 pub type int = i64; |
| 32 /// Typical floating point number type |
29 /// Typical floating point number type |
| 33 #[allow(non_camel_case_types)] |
30 #[allow(non_camel_case_types)] |
| 34 pub type float = f64; |
31 pub type float = f64; |
| 35 |
32 |
| 36 /// Casts of abstract numerical types to others via the standard `as` keyword. |
33 /// Casts of abstract numerical types to others via the standard `as` keyword. |
| 37 pub trait CastFrom<T : 'static + Copy> : num_traits::cast::AsPrimitive<T> { |
34 pub trait CastFrom<T: 'static + Copy>: num_traits::cast::AsPrimitive<T> { |
| 38 fn cast_from(other : T) -> Self; |
35 fn cast_from(other: T) -> Self; |
| 39 } |
36 } |
| 40 |
37 |
| 41 macro_rules! impl_casts { |
38 macro_rules! impl_casts { |
| 42 ($($type:ty)*) => { $( |
39 ($($type:ty)*) => { $( |
| 43 impl_casts!(@phase2, $type, |
40 impl_casts!(@phase2, $type, |
| 56 impl_casts!(u8 u16 u32 u64 u128 usize |
53 impl_casts!(u8 u16 u32 u64 u128 usize |
| 57 i8 i16 i32 i64 i128 isize |
54 i8 i16 i32 i64 i128 isize |
| 58 f32 f64); |
55 f32 f64); |
| 59 |
56 |
| 60 /// Trait for general numeric types |
57 /// Trait for general numeric types |
| 61 pub trait Num : 'static + Copy + Sync + Send + num::Num + num_traits::NumAssign |
58 pub trait Num: |
| 62 + std::iter::Sum + std::iter::Product |
59 'static |
| 63 + std::fmt::Debug + std::fmt::Display + serde::Serialize |
60 + Copy |
| 64 + CastFrom<u8> + CastFrom<u16> + CastFrom<u32> + CastFrom<u64> |
61 + Sync |
| 65 + CastFrom<u128> + CastFrom<usize> |
62 + Send |
| 66 + CastFrom<i8> + CastFrom<i16> + CastFrom<i32> + CastFrom<i64> |
63 + num::Num |
| 67 + CastFrom<i128> + CastFrom<isize> |
64 + num_traits::NumAssign |
| 68 + CastFrom<f32> + CastFrom<f64> |
65 + std::iter::Sum |
| 69 + crate::instance::Space { |
66 + std::iter::Product |
| 70 |
67 + std::fmt::Debug |
| 71 const ZERO : Self; |
68 + std::fmt::Display |
| 72 const ONE : Self; |
69 + serde::Serialize |
| 73 const TWO : Self; |
70 + CastFrom<u8> |
| |
71 + CastFrom<u16> |
| |
72 + CastFrom<u32> |
| |
73 + CastFrom<u64> |
| |
74 + CastFrom<u128> |
| |
75 + CastFrom<usize> |
| |
76 + CastFrom<i8> |
| |
77 + CastFrom<i16> |
| |
78 + CastFrom<i32> |
| |
79 + CastFrom<i64> |
| |
80 + CastFrom<i128> |
| |
81 + CastFrom<isize> |
| |
82 + CastFrom<f32> |
| |
83 + CastFrom<f64> |
| |
84 + crate::instance::ClosedSpace |
| |
85 { |
| |
86 const ZERO: Self; |
| |
87 const ONE: Self; |
| |
88 const TWO: Self; |
| 74 /// Generic version of `Self::MAX` |
89 /// Generic version of `Self::MAX` |
| 75 const RANGE_MAX : Self; |
90 const RANGE_MAX: Self; |
| 76 /// Generic version of `Self::MIN` |
91 /// Generic version of `Self::MIN` |
| 77 const RANGE_MIN : Self; |
92 const RANGE_MIN: Self; |
| 78 } |
93 } |
| 79 |
94 |
| 80 /// Trait for signed numeric types |
95 /// Trait for signed numeric types |
| 81 pub trait SignedNum : Num + num::Signed + std::ops::Neg<Output=Self> {} |
96 pub trait SignedNum: Num + num::Signed + std::ops::Neg<Output = Self> {} |
| 82 impl<U : Num + num::Signed + std::ops::Neg<Output=Self>> SignedNum for U { } |
97 impl<U: Num + num::Signed + std::ops::Neg<Output = Self>> SignedNum for U {} |
| 83 |
98 |
| 84 /// Trait for floating point numbers |
99 /// Trait for floating point numbers |
| 85 pub trait Float : SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ { |
100 pub trait Float: SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ { |
| 86 // An unsigned integer that can be used for indexing operations and |
101 // An unsigned integer that can be used for indexing operations and |
| 87 // converted to F without loss. |
102 // converted to F without loss. |
| 88 //type CompatibleSize : CompatibleUnsigned<Self>; |
103 //type CompatibleSize : CompatibleUnsigned<Self>; |
| 89 |
104 |
| 90 const PI : Self; |
105 const PI: Self; |
| 91 const E : Self; |
106 const E: Self; |
| 92 const EPSILON : Self; |
107 const EPSILON: Self; |
| 93 const SQRT_2 : Self; |
108 const SQRT_2: Self; |
| 94 const INFINITY : Self; |
109 const INFINITY: Self; |
| 95 const NEG_INFINITY : Self; |
110 const NEG_INFINITY: Self; |
| 96 const NAN : Self; |
111 const NAN: Self; |
| 97 const FRAC_2_SQRT_PI : Self; |
112 const FRAC_2_SQRT_PI: Self; |
| 98 } |
113 } |
| 99 |
114 |
| 100 /// Trait for integers |
115 /// Trait for integers |
| 101 pub trait Integer : Num + num::Integer {} |
116 pub trait Integer: Num + num::Integer {} |
| 102 |
117 |
| 103 /// Trait for unsigned integers |
118 /// Trait for unsigned integers |
| 104 pub trait Unsigned : Num + Integer + num::Unsigned {} |
119 pub trait Unsigned: Num + Integer + num::Unsigned {} |
| 105 |
120 |
| 106 /// Trait for signed integers |
121 /// Trait for signed integers |
| 107 pub trait Signed : SignedNum + Integer {} |
122 pub trait Signed: SignedNum + Integer {} |
| 108 |
123 |
| 109 macro_rules! impl_num_consts { |
124 macro_rules! impl_num_consts { |
| 110 ($($type:ty)*) => { $( |
125 ($($type:ty)*) => { $( |
| 111 impl Num for $type { |
126 impl Num for $type { |
| 112 const ZERO : Self = 0 as $type; |
127 const ZERO : Self = 0 as $type; |
| 135 /*#[cfg(any(target_pointer_width = "128", target_pointer_width = "64"))] |
150 /*#[cfg(any(target_pointer_width = "128", target_pointer_width = "64"))] |
| 136 type CompatibleSize = u32; |
151 type CompatibleSize = u32; |
| 137 #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] |
152 #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] |
| 138 type CompatibleSize = usize;*/ |
153 type CompatibleSize = usize;*/ |
| 139 |
154 |
| 140 const PI : Self = std::f64::consts::PI; |
155 const PI: Self = std::f64::consts::PI; |
| 141 const E : Self = std::f64::consts::E; |
156 const E: Self = std::f64::consts::E; |
| 142 const EPSILON : Self = std::f64::EPSILON; |
157 const EPSILON: Self = std::f64::EPSILON; |
| 143 const SQRT_2 : Self = std::f64::consts::SQRT_2; |
158 const SQRT_2: Self = std::f64::consts::SQRT_2; |
| 144 const INFINITY : Self = std::f64::INFINITY; |
159 const INFINITY: Self = std::f64::INFINITY; |
| 145 const NEG_INFINITY : Self = std::f64::NEG_INFINITY; |
160 const NEG_INFINITY: Self = std::f64::NEG_INFINITY; |
| 146 const NAN : Self = std::f64::NAN; |
161 const NAN: Self = std::f64::NAN; |
| 147 const FRAC_2_SQRT_PI : Self = std::f64::consts::FRAC_2_SQRT_PI; |
162 const FRAC_2_SQRT_PI: Self = std::f64::consts::FRAC_2_SQRT_PI; |
| 148 } |
163 } |
| 149 |
164 |
| 150 impl Float for f32 { |
165 impl Float for f32 { |
| 151 /* |
166 /* |
| 152 #[cfg(any(target_pointer_width = "128", target_pointer_width = "64", target_pointer_width = "32"))] |
167 #[cfg(any(target_pointer_width = "128", target_pointer_width = "64", target_pointer_width = "32"))] |
| 153 type CompatibleSize = u16; |
168 type CompatibleSize = u16; |
| 154 #[cfg(any(target_pointer_width = "16"))] |
169 #[cfg(any(target_pointer_width = "16"))] |
| 155 type CompatibleSize = usize; |
170 type CompatibleSize = usize; |
| 156 */ |
171 */ |
| 157 |
172 |
| 158 const PI : Self = std::f32::consts::PI; |
173 const PI: Self = std::f32::consts::PI; |
| 159 const E : Self = std::f32::consts::E; |
174 const E: Self = std::f32::consts::E; |
| 160 const EPSILON : Self = std::f32::EPSILON; |
175 const EPSILON: Self = std::f32::EPSILON; |
| 161 const SQRT_2 : Self = std::f32::consts::SQRT_2; |
176 const SQRT_2: Self = std::f32::consts::SQRT_2; |
| 162 const INFINITY : Self = std::f32::INFINITY; |
177 const INFINITY: Self = std::f32::INFINITY; |
| 163 const NEG_INFINITY : Self = std::f32::NEG_INFINITY; |
178 const NEG_INFINITY: Self = std::f32::NEG_INFINITY; |
| 164 const NAN : Self = std::f32::NAN; |
179 const NAN: Self = std::f32::NAN; |
| 165 const FRAC_2_SQRT_PI : Self = std::f32::consts::FRAC_2_SQRT_PI; |
180 const FRAC_2_SQRT_PI: Self = std::f32::consts::FRAC_2_SQRT_PI; |
| 166 } |
181 } |
| 167 |
182 |
| 168 /* |
183 /* |
| 169 trait_set! { |
184 trait_set! { |
| 170 pub trait CompatibleUnsigned<F : Float> = Unsigned + Into<F>; |
185 pub trait CompatibleUnsigned<F : Float> = Unsigned + Into<F>; |
| 171 pub trait CompatibleSigned<F : Float> = Signed + Into<F>; |
186 pub trait CompatibleSigned<F : Float> = Signed + Into<F>; |
| 172 } |
187 } |
| 173 */ |
188 */ |
| 174 |
|