ombre: Add a few more math trait implementations

7bf366594e2426ffe24b6487cfa539754da72609
Alexis Sellier committed ago 1 parent fd8e7e26
ombre/src/math/traits.rs +48 -0
120 120
    fn is_one(&self) -> bool {
121 121
        self == &Self::ONE
122 122
    }
123 123
}
124 124
125 +
impl One for u32 {
126 +
    const ONE: u32 = 1;
127 +
128 +
    fn is_one(&self) -> bool {
129 +
        self == &Self::ONE
130 +
    }
131 +
}
132 +
125 133
impl One for u64 {
126 134
    const ONE: u64 = 1;
127 135
128 136
    fn is_one(&self) -> bool {
129 137
        self == &Self::ONE
130 138
    }
131 139
}
132 140
141 +
impl One for i32 {
142 +
    const ONE: i32 = 1;
143 +
144 +
    fn is_one(&self) -> bool {
145 +
        self == &Self::ONE
146 +
    }
147 +
}
148 +
133 149
impl One for NonZeroU8 {
134 150
    const ONE: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(u8::ONE) };
135 151
136 152
    fn is_one(&self) -> bool {
137 153
        self == &Self::ONE
244 260
    fn from_u64(other: u64) -> Self;
245 261
    /// Converts this integer to f64.
246 262
    fn as_f64(&self) -> f64;
247 263
}
248 264
265 +
impl Integer for u32 {
266 +
    const BITS: u32 = u32::BITS;
267 +
268 +
    fn rem(&self, other: Self) -> Self {
269 +
        self % other
270 +
    }
271 +
272 +
    fn from_u64(other: u64) -> Self {
273 +
        other as u32
274 +
    }
275 +
276 +
    fn as_f64(&self) -> f64 {
277 +
        *self as f64
278 +
    }
279 +
}
280 +
281 +
impl Integer for i32 {
282 +
    const BITS: u32 = i32::BITS;
283 +
284 +
    fn rem(&self, other: Self) -> Self {
285 +
        self % other
286 +
    }
287 +
288 +
    fn from_u64(other: u64) -> Self {
289 +
        other as i32
290 +
    }
291 +
292 +
    fn as_f64(&self) -> f64 {
293 +
        *self as f64
294 +
    }
295 +
}
296 +
249 297
impl Integer for u64 {
250 298
    const BITS: u32 = u64::BITS;
251 299
252 300
    fn rem(&self, other: Self) -> Self {
253 301
        self % other