|
15 | 15 | html_playground_url = "http://play.integer32.com/")]
|
16 | 16 |
|
17 | 17 | use std::ops::{Add, Sub, Mul, Div, Rem};
|
| 18 | +use std::num::Wrapping; |
18 | 19 |
|
19 | 20 | pub use bounds::Bounded;
|
20 | 21 | pub use float::{Float, FloatConst};
|
@@ -74,6 +75,18 @@ macro_rules! int_trait_impl {
|
74 | 75 | }
|
75 | 76 | int_trait_impl!(Num for usize u8 u16 u32 u64 isize i8 i16 i32 i64);
|
76 | 77 |
|
| 78 | +impl<T: Num> Num for Wrapping<T> |
| 79 | + where Wrapping<T>: |
| 80 | + Add<Output = Wrapping<T>> + Sub<Output = Wrapping<T>> |
| 81 | + + Mul<Output = Wrapping<T>> + Div<Output = Wrapping<T>> + Rem<Output = Wrapping<T>> |
| 82 | +{ |
| 83 | + type FromStrRadixErr = T::FromStrRadixErr; |
| 84 | + fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr> { |
| 85 | + T::from_str_radix(str, radix).map(Wrapping) |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | + |
77 | 90 | #[derive(Debug)]
|
78 | 91 | pub enum FloatErrorKind {
|
79 | 92 | Empty,
|
@@ -243,9 +256,9 @@ float_trait_impl!(Num for f32 f64);
|
243 | 256 |
|
244 | 257 | /// A value bounded by a minimum and a maximum
|
245 | 258 | ///
|
246 |
| -/// If input is less than min then this returns min. |
247 |
| -/// If input is greater than max then this returns max. |
248 |
| -/// Otherwise this returns input. |
| 259 | +/// If input is less than min then this returns min. |
| 260 | +/// If input is greater than max then this returns max. |
| 261 | +/// Otherwise this returns input. |
249 | 262 | #[inline]
|
250 | 263 | pub fn clamp<T: PartialOrd>(input: T, min: T, max: T) -> T {
|
251 | 264 | debug_assert!(min <= max, "min must be less than or equal to max");
|
|
0 commit comments