about summary refs log tree commit diff
path: root/tests/ui/modulo_arithmetic_float.rs
blob: b010b0dbdfa69e5c241745a70ddf6eaef7a1d42a (plain)
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
#![warn(clippy::modulo_arithmetic)]
#![allow(
    unused,
    clippy::shadow_reuse,
    clippy::shadow_unrelated,
    clippy::no_effect,
    clippy::unnecessary_operation,
    clippy::modulo_one
)]

fn main() {
    // Lint when both sides are const and of the opposite sign
    -1.6 % 2.1;
    1.6 % -2.1;
    (1.1 - 2.3) % (1.1 + 2.3);
    (1.1 + 2.3) % (1.1 - 2.3);

    // Lint on floating point numbers
    let a_f32: f32 = -1.6;
    let mut b_f32: f32 = 2.1;
    a_f32 % b_f32;
    b_f32 % a_f32;
    b_f32 %= a_f32;

    let a_f64: f64 = -1.6;
    let mut b_f64: f64 = 2.1;
    a_f64 % b_f64;
    b_f64 % a_f64;
    b_f64 %= a_f64;

    // No lint when both sides are const and of the same sign
    1.6 % 2.1;
    -1.6 % -2.1;
    (1.1 + 2.3) % (-1.1 + 2.3);
    (-1.1 - 2.3) % (1.1 - 2.3);
}