Trait rotary_add::CycleAdd
source · pub trait CycleAdd<T: Add<Output = T> + Sub<Output = T> + PartialEq + Copy> {
// Required methods
fn cycle_add(&self, other: &T, base: T) -> T;
fn cycle_sub(&self, other: &T, base: T) -> T;
fn series_add(&self, other: &T, limit: T) -> T;
fn series_sub(&self, other: &T, limit: T) -> T;
fn series_mod(&self, limit: T) -> T;
}
Expand description
CycleAdd works on range from 0 to a a specified base. The max value is 1 less than the base Trait with methods for cyclical arithmetic with unsigned integers Values rotate within a range of zero to 1 below the specified base, when normal addition or subtraction would yield out-of-range values
Required Methods§
sourcefn cycle_add(&self, other: &T, base: T) -> T
fn cycle_add(&self, other: &T, base: T) -> T
Add another unsigned integer and start from zero again if the result is out of range. With a a base of 60 applied to a u8 value, 53.cycle_add(10, 60) is thus 3
sourcefn cycle_sub(&self, other: &T, base: T) -> T
fn cycle_sub(&self, other: &T, base: T) -> T
Subtract another unsigned integer and start from a specified base if the target result may be otherwise be negative if it were a signed integer e.g. if a base of 24 is applied to a u8 value, its max is 23 3.cycle_sub(4) is thus 23
sourcefn series_add(&self, other: &T, limit: T) -> T
fn series_add(&self, other: &T, limit: T) -> T
Add another unsigned integer representing a number in a series from 1 to specified maximum Unlike cycle_add the max value is the limit and the minimum value is 1. Hence 1.series_add(7, 1) will be 1
sourcefn series_sub(&self, other: &T, limit: T) -> T
fn series_sub(&self, other: &T, limit: T) -> T
Subtract another unsigned integer representing a number in a series from 1 to specified maximum Unlike cycle_sub the max value is the limit and the minimum value is 1. Hence 1.series_sub(1, 7) will be 7
sourcefn series_mod(&self, limit: T) -> T
fn series_mod(&self, limit: T) -> T
Find the remainder in a range between one and a limit.
This methods normalises an unsigned integer within a series
from 1 to specified limit
Unlike % or T.mod(T) 0.series_mod(&T) will equal the limit as results cannot be lower than 1
This is mainly used for arbitrary series like weekday numbers 1 to 7 or month numbers 1 to 31
The specified limit may be no higher than the unsigned type’s MAX
e.g. 255 for u8