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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Appellation: utils <module>
Contrib: FL03 <jo3mccain@icloud.com>
*/
use ;
/// Computes the `absmod` of the value given a modulus.
/// The modulo is calculated before determining if
/// the value is positive or negative.
/// If negative, the value is reflected by adding the modulus
/// before taking the modulo again.
///
/// # Example
///
/// ```rust
/// use rstmt_core::absmod;
///
/// assert_eq!(absmod(22, 12), 22 % 12);
/// assert_ne!(absmod(-17, 12), (-17 % 12).abs());
/// assert_eq!(absmod(-17, 12), 7);
/// ```
/// A functional implementation of python's `%` operator. The implementation
/// is unique in its handling of negative values, uniquely preseving the sign
/// of the _denominator_.