irox_tools/primitives/
wrapping.rs

1// SPDX-License-Identifier: MIT
2// Copyright 2024 IROX Contributors
3//
4
5///
6/// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the type.
7pub trait WrappingAdd {
8    #[must_use]
9    /// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at the boundary of the type.
10    fn wrapping_add(&self, rhs: Self) -> Self;
11}
12
13///
14/// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the boundary of the type.
15pub trait WrappingSub {
16    #[must_use]
17    /// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the boundary of the type.
18    fn wrapping_sub(&self, rhs: Self) -> Self;
19}
20
21///
22/// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at the boundary of the type.
23pub trait WrappingMul {
24    #[must_use]
25    /// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at the boundary of the type.
26    fn wrapping_mul(&self, rhs: Self) -> Self;
27}