Trait rotary_add::RotaryAdd
source · pub trait RotaryAdd<T: Add<Output = T> + Sub<Output = T> + PartialEq + Copy> {
// Required methods
fn rotary_add(&self, other: &T) -> T;
fn rotary_sub(&self, other: &T) -> T;
}
Expand description
RotaryAdd works on the whole range of the unsigned integer Trait with methods for cyclical or rotary arithmetic with unsigned integers When additions or subtractions may otherwise overflow, either falling below zero or above the type’s maximum, the values rotate. This is mainly for use with cryptography
Required Methods§
sourcefn rotary_add(&self, other: &T) -> T
fn rotary_add(&self, other: &T) -> T
Add another unsigned integer and start from zero again should value overflow, but retaining the remainder With u8, 255.rotary_add(4) is thus 3
sourcefn rotary_sub(&self, other: &T) -> T
fn rotary_sub(&self, other: &T) -> T
Subtract another unsigned integer and start from the type’s max value if the target result may be otherwise be negative if it were a signed integer e.g. with u8 the max is 255 (allowing for 256 values including zero) 3.rotary_sub(4) is thus 255