irox_tools/primitives/
wrapping.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: MIT
// Copyright 2024 IROX Contributors
//

///
/// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the type.
pub trait WrappingAdd {
    #[must_use]
    /// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the type.
    fn wrapping_add(&self, rhs: Self) -> Self;
}

///
/// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the boundary of the type.
pub trait WrappingSub {
    #[must_use]
    /// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the boundary of the type.
    fn wrapping_sub(&self, rhs: Self) -> Self;
}

///
/// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at the boundary of the type.
pub trait WrappingMul {
    #[must_use]
    /// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at the boundary of the type.
    fn wrapping_mul(&self, rhs: Self) -> Self;
}