]> git.lizzy.rs Git - rust.git/blob - src/docs/modulo_one.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / modulo_one.txt
1 ### What it does
2 Checks for getting the remainder of a division by one or minus
3 one.
4
5 ### Why is this bad?
6 The result for a divisor of one can only ever be zero; for
7 minus one it can cause panic/overflow (if the left operand is the minimal value of
8 the respective integer type) or results in zero. No one will write such code
9 deliberately, unless trying to win an Underhanded Rust Contest. Even for that
10 contest, it's probably a bad idea. Use something more underhanded.
11
12 ### Example
13 ```
14 let a = x % 1;
15 let a = x % -1;
16 ```