| 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; |
| |
36 } |
| |
37 |
| |
38 mod private { |
| |
39 pub trait NumSeal {} |
| 39 } |
40 } |
| 40 |
41 |
| 41 macro_rules! impl_casts { |
42 macro_rules! impl_casts { |
| 42 ($($type:ty)*) => { $( |
43 ($($type:ty)*) => { $( |
| 43 impl_casts!(@phase2, $type, |
44 impl_casts!(@phase2, $type, |
| 56 impl_casts!(u8 u16 u32 u64 u128 usize |
57 impl_casts!(u8 u16 u32 u64 u128 usize |
| 57 i8 i16 i32 i64 i128 isize |
58 i8 i16 i32 i64 i128 isize |
| 58 f32 f64); |
59 f32 f64); |
| 59 |
60 |
| 60 /// Trait for general numeric types |
61 /// Trait for general numeric types |
| 61 pub trait Num : 'static + Copy + Sync + Send + num::Num + num_traits::NumAssign |
62 pub trait Num: |
| 62 + std::iter::Sum + std::iter::Product |
63 'static |
| 63 + std::fmt::Debug + std::fmt::Display + serde::Serialize |
64 + Copy |
| 64 + CastFrom<u8> + CastFrom<u16> + CastFrom<u32> + CastFrom<u64> |
65 + Sync |
| 65 + CastFrom<u128> + CastFrom<usize> |
66 + Send |
| 66 + CastFrom<i8> + CastFrom<i16> + CastFrom<i32> + CastFrom<i64> |
67 + num::Num |
| 67 + CastFrom<i128> + CastFrom<isize> |
68 + num_traits::NumAssign |
| 68 + CastFrom<f32> + CastFrom<f64> |
69 + std::iter::Sum |
| 69 + crate::instance::Space { |
70 + std::iter::Product |
| 70 |
71 + std::fmt::Debug |
| 71 const ZERO : Self; |
72 + std::fmt::Display |
| 72 const ONE : Self; |
73 + serde::Serialize |
| 73 const TWO : Self; |
74 + CastFrom<u8> |
| |
75 + CastFrom<u16> |
| |
76 + CastFrom<u32> |
| |
77 + CastFrom<u64> |
| |
78 + CastFrom<u128> |
| |
79 + CastFrom<usize> |
| |
80 + CastFrom<i8> |
| |
81 + CastFrom<i16> |
| |
82 + CastFrom<i32> |
| |
83 + CastFrom<i64> |
| |
84 + CastFrom<i128> |
| |
85 + CastFrom<isize> |
| |
86 + CastFrom<f32> |
| |
87 + CastFrom<f64> |
| |
88 + crate::instance::Space |
| |
89 + private::NumSeal |
| |
90 { |
| |
91 const ZERO: Self; |
| |
92 const ONE: Self; |
| |
93 const TWO: Self; |
| 74 /// Generic version of `Self::MAX` |
94 /// Generic version of `Self::MAX` |
| 75 const RANGE_MAX : Self; |
95 const RANGE_MAX: Self; |
| 76 /// Generic version of `Self::MIN` |
96 /// Generic version of `Self::MIN` |
| 77 const RANGE_MIN : Self; |
97 const RANGE_MIN: Self; |
| 78 } |
98 } |
| 79 |
99 |
| 80 /// Trait for signed numeric types |
100 /// Trait for signed numeric types |
| 81 pub trait SignedNum : Num + num::Signed + std::ops::Neg<Output=Self> {} |
101 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 { } |
102 impl<U: Num + num::Signed + std::ops::Neg<Output = Self>> SignedNum for U {} |
| 83 |
103 |
| 84 /// Trait for floating point numbers |
104 /// Trait for floating point numbers |
| 85 pub trait Float : SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ { |
105 pub trait Float: SignedNum + num::Float /*+ From<Self::CompatibleSize>*/ { |
| 86 // An unsigned integer that can be used for indexing operations and |
106 // An unsigned integer that can be used for indexing operations and |
| 87 // converted to F without loss. |
107 // converted to F without loss. |
| 88 //type CompatibleSize : CompatibleUnsigned<Self>; |
108 //type CompatibleSize : CompatibleUnsigned<Self>; |
| 89 |
109 |
| 90 const PI : Self; |
110 const PI: Self; |
| 91 const E : Self; |
111 const E: Self; |
| 92 const EPSILON : Self; |
112 const EPSILON: Self; |
| 93 const SQRT_2 : Self; |
113 const SQRT_2: Self; |
| 94 const INFINITY : Self; |
114 const INFINITY: Self; |
| 95 const NEG_INFINITY : Self; |
115 const NEG_INFINITY: Self; |
| 96 const NAN : Self; |
116 const NAN: Self; |
| 97 const FRAC_2_SQRT_PI : Self; |
117 const FRAC_2_SQRT_PI: Self; |
| 98 } |
118 } |
| 99 |
119 |
| 100 /// Trait for integers |
120 /// Trait for integers |
| 101 pub trait Integer : Num + num::Integer {} |
121 pub trait Integer: Num + num::Integer {} |
| 102 |
122 |
| 103 /// Trait for unsigned integers |
123 /// Trait for unsigned integers |
| 104 pub trait Unsigned : Num + Integer + num::Unsigned {} |
124 pub trait Unsigned: Num + Integer + num::Unsigned {} |
| 105 |
125 |
| 106 /// Trait for signed integers |
126 /// Trait for signed integers |
| 107 pub trait Signed : SignedNum + Integer {} |
127 pub trait Signed: SignedNum + Integer {} |
| 108 |
128 |
| 109 macro_rules! impl_num_consts { |
129 macro_rules! impl_num_consts { |
| 110 ($($type:ty)*) => { $( |
130 ($($type:ty)*) => { $( |
| 111 impl Num for $type { |
131 impl Num for $type { |
| 112 const ZERO : Self = 0 as $type; |
132 const ZERO : Self = 0 as $type; |
| 121 macro_rules! impl_integers { |
141 macro_rules! impl_integers { |
| 122 ($signed:ty : $($type:ty)*) => { $( |
142 ($signed:ty : $($type:ty)*) => { $( |
| 123 impl_num_consts!($type); |
143 impl_num_consts!($type); |
| 124 impl Integer for $type {} |
144 impl Integer for $type {} |
| 125 impl $signed for $type {} |
145 impl $signed for $type {} |
| |
146 impl private::NumSeal for $type {} |
| 126 )* } |
147 )* } |
| 127 } |
148 } |
| 128 |
149 |
| 129 impl_integers!(Signed: i8 i16 i32 i64 i128 isize); |
150 impl_integers!(Signed: i8 i16 i32 i64 i128 isize); |
| 130 impl_integers!(Unsigned: u8 u16 u32 u64 u128 usize); |
151 impl_integers!(Unsigned: u8 u16 u32 u64 u128 usize); |
| 135 /*#[cfg(any(target_pointer_width = "128", target_pointer_width = "64"))] |
156 /*#[cfg(any(target_pointer_width = "128", target_pointer_width = "64"))] |
| 136 type CompatibleSize = u32; |
157 type CompatibleSize = u32; |
| 137 #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] |
158 #[cfg(any(target_pointer_width = "32", target_pointer_width = "16"))] |
| 138 type CompatibleSize = usize;*/ |
159 type CompatibleSize = usize;*/ |
| 139 |
160 |
| 140 const PI : Self = std::f64::consts::PI; |
161 const PI: Self = std::f64::consts::PI; |
| 141 const E : Self = std::f64::consts::E; |
162 const E: Self = std::f64::consts::E; |
| 142 const EPSILON : Self = std::f64::EPSILON; |
163 const EPSILON: Self = std::f64::EPSILON; |
| 143 const SQRT_2 : Self = std::f64::consts::SQRT_2; |
164 const SQRT_2: Self = std::f64::consts::SQRT_2; |
| 144 const INFINITY : Self = std::f64::INFINITY; |
165 const INFINITY: Self = std::f64::INFINITY; |
| 145 const NEG_INFINITY : Self = std::f64::NEG_INFINITY; |
166 const NEG_INFINITY: Self = std::f64::NEG_INFINITY; |
| 146 const NAN : Self = std::f64::NAN; |
167 const NAN: Self = std::f64::NAN; |
| 147 const FRAC_2_SQRT_PI : Self = std::f64::consts::FRAC_2_SQRT_PI; |
168 const FRAC_2_SQRT_PI: Self = std::f64::consts::FRAC_2_SQRT_PI; |
| 148 } |
169 } |
| 149 |
170 |
| 150 impl Float for f32 { |
171 impl Float for f32 { |
| 151 /* |
172 /* |
| 152 #[cfg(any(target_pointer_width = "128", target_pointer_width = "64", target_pointer_width = "32"))] |
173 #[cfg(any(target_pointer_width = "128", target_pointer_width = "64", target_pointer_width = "32"))] |
| 153 type CompatibleSize = u16; |
174 type CompatibleSize = u16; |
| 154 #[cfg(any(target_pointer_width = "16"))] |
175 #[cfg(any(target_pointer_width = "16"))] |
| 155 type CompatibleSize = usize; |
176 type CompatibleSize = usize; |
| 156 */ |
177 */ |
| 157 |
178 |
| 158 const PI : Self = std::f32::consts::PI; |
179 const PI: Self = std::f32::consts::PI; |
| 159 const E : Self = std::f32::consts::E; |
180 const E: Self = std::f32::consts::E; |
| 160 const EPSILON : Self = std::f32::EPSILON; |
181 const EPSILON: Self = std::f32::EPSILON; |
| 161 const SQRT_2 : Self = std::f32::consts::SQRT_2; |
182 const SQRT_2: Self = std::f32::consts::SQRT_2; |
| 162 const INFINITY : Self = std::f32::INFINITY; |
183 const INFINITY: Self = std::f32::INFINITY; |
| 163 const NEG_INFINITY : Self = std::f32::NEG_INFINITY; |
184 const NEG_INFINITY: Self = std::f32::NEG_INFINITY; |
| 164 const NAN : Self = std::f32::NAN; |
185 const NAN: Self = std::f32::NAN; |
| 165 const FRAC_2_SQRT_PI : Self = std::f32::consts::FRAC_2_SQRT_PI; |
186 const FRAC_2_SQRT_PI: Self = std::f32::consts::FRAC_2_SQRT_PI; |
| 166 } |
187 } |
| |
188 |
| |
189 impl private::NumSeal for f32 {} |
| |
190 impl private::NumSeal for f64 {} |
| 167 |
191 |
| 168 /* |
192 /* |
| 169 trait_set! { |
193 trait_set! { |
| 170 pub trait CompatibleUnsigned<F : Float> = Unsigned + Into<F>; |
194 pub trait CompatibleUnsigned<F : Float> = Unsigned + Into<F>; |
| 171 pub trait CompatibleSigned<F : Float> = Signed + Into<F>; |
195 pub trait CompatibleSigned<F : Float> = Signed + Into<F>; |
| 172 } |
196 } |
| 173 */ |
197 */ |
| 174 |
|