Is there a modulus (not remainder) function / operation?

前端 未结 4 2021
粉色の甜心
粉色の甜心 2020-12-14 05:31

In Rust (like most programming languages), the % operator performs the remainder operation, not the modulus operation. These operations have d

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-14 05:59

    From the other answers I constructed:

    fn n_mod_m  + std::ops::Add + Copy>
      (n: T, m: T) -> T {
        ((n % m) + m) % m
    }
    
    assert_eq!(n_mod_m(-21, 4), 3);
    

提交回复
热议问题