Skip to content

Commit d833428

Browse files
authored
Merge pull request rust-lang#355 from tgross35/clippy
Fix clippy lints
2 parents 338d953 + e8c0f68 commit d833428

31 files changed

+315
-307
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ jobs:
8282
[ -n "${{ matrix.channel }}" ] && channel="${{ matrix.channel }}"
8383
rustup update "$channel" --no-self-update
8484
rustup default "$channel"
85-
rustup target add ${{ matrix.target }}
86-
rustup component add llvm-tools-preview
85+
rustup target add "${{ matrix.target }}"
86+
rustup component add clippy llvm-tools-preview
8787
- uses: Swatinem/rust-cache@v2
8888
with:
8989
key: ${{ matrix.target }}
@@ -105,6 +105,12 @@ jobs:
105105
rustup target add x86_64-unknown-linux-musl
106106
cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
107107
108+
- name: Clippy
109+
run: |
110+
# Run clippy on `libm`
111+
cargo clippy --target "${{ matrix.target }}" --package libm
112+
113+
108114
builtins:
109115
name: Check use with compiler-builtins
110116
runs-on: ubuntu-latest

ci/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,4 @@ else
8888
$cmd --benches
8989
$cmd --benches --release
9090
fi
91+

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
#![allow(clippy::assign_op_pattern)]
66
#![allow(clippy::deprecated_cfg_attr)]
77
#![allow(clippy::eq_op)]
8+
#![allow(clippy::excessive_precision)]
89
#![allow(clippy::float_cmp)]
910
#![allow(clippy::int_plus_one)]
1011
#![allow(clippy::many_single_char_names)]
1112
#![allow(clippy::mixed_case_hex_literals)]
13+
#![allow(clippy::needless_late_init)]
1214
#![allow(clippy::needless_return)]
1315
#![allow(clippy::unreadable_literal)]
16+
#![allow(clippy::zero_divided_by_zero)]
1417

1518
mod libm_helper;
1619
mod math;

src/math/asin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn asin(mut x: f64) -> f64 {
9090
/* |x| < 0.5 */
9191
if ix < 0x3fe00000 {
9292
/* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */
93-
if ix < 0x3e500000 && ix >= 0x00100000 {
93+
if (0x00100000..0x3e500000).contains(&ix) {
9494
return x;
9595
} else {
9696
return x + x * comp_r(x * x);

src/math/asinf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn asinf(mut x: f32) -> f32 {
5454
if ix < 0x3f000000 {
5555
/* |x| < 0.5 */
5656
/* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */
57-
if (ix < 0x39800000) && (ix >= 0x00800000) {
57+
if (0x00800000..0x39800000).contains(&ix) {
5858
return x;
5959
}
6060
return x + x * r(x * x);

src/math/atan2f.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ pub fn atan2f(y: f32, x: f32) -> f32 {
4242
/* when y = 0 */
4343
if iy == 0 {
4444
return match m {
45-
0 | 1 => y, /* atan(+-0,+anything)=+-0 */
46-
2 => PI, /* atan(+0,-anything) = pi */
47-
3 | _ => -PI, /* atan(-0,-anything) =-pi */
45+
0 | 1 => y, /* atan(+-0,+anything)=+-0 */
46+
2 => PI, /* atan(+0,-anything) = pi */
47+
_ => -PI, /* atan(-0,-anything) =-pi */
4848
};
4949
}
5050
/* when x = 0 */
@@ -55,17 +55,17 @@ pub fn atan2f(y: f32, x: f32) -> f32 {
5555
if ix == 0x7f800000 {
5656
return if iy == 0x7f800000 {
5757
match m {
58-
0 => PI / 4., /* atan(+INF,+INF) */
59-
1 => -PI / 4., /* atan(-INF,+INF) */
60-
2 => 3. * PI / 4., /* atan(+INF,-INF)*/
61-
3 | _ => -3. * PI / 4., /* atan(-INF,-INF)*/
58+
0 => PI / 4., /* atan(+INF,+INF) */
59+
1 => -PI / 4., /* atan(-INF,+INF) */
60+
2 => 3. * PI / 4., /* atan(+INF,-INF)*/
61+
_ => -3. * PI / 4., /* atan(-INF,-INF)*/
6262
}
6363
} else {
6464
match m {
65-
0 => 0., /* atan(+...,+INF) */
66-
1 => -0., /* atan(-...,+INF) */
67-
2 => PI, /* atan(+...,-INF) */
68-
3 | _ => -PI, /* atan(-...,-INF) */
65+
0 => 0., /* atan(+...,+INF) */
66+
1 => -0., /* atan(-...,+INF) */
67+
2 => PI, /* atan(+...,-INF) */
68+
_ => -PI, /* atan(-...,-INF) */
6969
}
7070
};
7171
}

src/math/atanhf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn atanhf(mut x: f32) -> f32 {
1818
if u < 0x3f800000 - (32 << 23) {
1919
/* handle underflow */
2020
if u < (1 << 23) {
21-
force_eval!((x * x) as f32);
21+
force_eval!(x * x);
2222
}
2323
} else {
2424
/* |x| < 0.5, up to 1.7ulp error */

src/math/exp2f.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn exp2f(mut x: f32) -> f32 {
9595
/* NaN */
9696
return x;
9797
}
98-
if ui >= 0x43000000 && ui < 0x80000000 {
98+
if (0x43000000..0x80000000).contains(&ui) {
9999
/* x >= 128 */
100100
x *= x1p127;
101101
return x;
@@ -127,7 +127,7 @@ pub fn exp2f(mut x: f32) -> f32 {
127127
let z: f64 = (x - uf) as f64;
128128
/* Compute r = exp2(y) = exp2ft[i0] * p(z). */
129129
let r: f64 = f64::from_bits(i!(EXP2FT, i0 as usize));
130-
let t: f64 = r as f64 * z;
130+
let t: f64 = r * z;
131131
let r: f64 = r + t * (p1 as f64 + z * p2 as f64) + t * (z * z) * (p3 as f64 + z * p4 as f64);
132132

133133
/* Scale by 2**k */

src/math/expm1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn expm1(mut x: f64) -> f64 {
115115
}
116116
ui = ((0x3ff + k) as u64) << 52; /* 2^k */
117117
let twopk = f64::from_bits(ui);
118-
if k < 0 || k > 56 {
118+
if !(0..=56).contains(&k) {
119119
/* suffice to return exp(x)-1 */
120120
y = x - e + 1.0;
121121
if k == 1024 {

src/math/expm1f.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn expm1f(mut x: f32) -> f32 {
115115
return 1. + 2. * (x - e);
116116
}
117117
let twopk = f32::from_bits(((0x7f + k) << 23) as u32); /* 2^k */
118-
if (k < 0) || (k > 56) {
118+
if !(0..=56).contains(&k) {
119119
/* suffice to return exp(x)-1 */
120120
let mut y = x - e + 1.;
121121
if k == 128 {

src/math/fabs.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use core::u64;
2-
31
/// Absolute value (magnitude) (f64)
42
/// Calculates the absolute value (magnitude) of the argument `x`,
53
/// by direct manipulation of the bit representation of `x`.

src/math/fdim.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use core::f64;
33
/// Positive difference (f64)
44
///
55
/// Determines the positive difference between arguments, returning:
6-
/// * x - y if x > y, or
7-
/// * +0 if x <= y, or
8-
/// * NAN if either argument is NAN.
6+
/// * x - y if x > y, or
7+
/// * +0 if x <= y, or
8+
/// * NAN if either argument is NAN.
99
///
1010
/// A range error may occur.
1111
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]

src/math/fdimf.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use core::f32;
33
/// Positive difference (f32)
44
///
55
/// Determines the positive difference between arguments, returning:
6-
/// * x - y if x > y, or
7-
/// * +0 if x <= y, or
8-
/// * NAN if either argument is NAN.
6+
/// * x - y if x > y, or
7+
/// * +0 if x <= y, or
8+
/// * NAN if either argument is NAN.
99
///
1010
/// A range error may occur.
1111
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]

src/math/fmaf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn fmaf(x: f32, y: f32, mut z: f32) -> f32 {
7171
underflow may not be raised correctly, example:
7272
fmaf(0x1p-120f, 0x1p-120f, 0x1p-149f)
7373
*/
74-
if e < 0x3ff - 126 && e >= 0x3ff - 149 && fetestexcept(FE_INEXACT) != 0 {
74+
if ((0x3ff - 149)..(0x3ff - 126)).contains(&e) && fetestexcept(FE_INEXACT) != 0 {
7575
feclearexcept(FE_INEXACT);
7676
// prevent `xy + vz` from being CSE'd with `xy + z` above
7777
let vz: f32 = unsafe { read_volatile(&z) };

src/math/fmod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use core::u64;
2-
31
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
42
pub fn fmod(x: f64, y: f64) -> f64 {
53
let mut uxi = x.to_bits();
@@ -74,7 +72,7 @@ pub fn fmod(x: f64, y: f64) -> f64 {
7472
} else {
7573
uxi >>= -ex + 1;
7674
}
77-
uxi |= (sx as u64) << 63;
75+
uxi |= sx << 63;
7876

7977
f64::from_bits(uxi)
8078
}

src/math/fmodf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::{f32, u32};
1+
use core::f32;
22

33
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
44
pub fn fmodf(x: f32, y: f32) -> f32 {

src/math/ilogb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn ilogb(x: f64) -> i32 {
2121
e
2222
} else if e == 0x7ff {
2323
force_eval!(0.0 / 0.0);
24-
if (i << 12) != 0 { FP_ILOGBNAN } else { i32::max_value() }
24+
if (i << 12) != 0 { FP_ILOGBNAN } else { i32::MAX }
2525
} else {
2626
e - 0x3ff
2727
}

src/math/ilogbf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub fn ilogbf(x: f32) -> i32 {
2121
e
2222
} else if e == 0xff {
2323
force_eval!(0.0 / 0.0);
24-
if (i << 9) != 0 { FP_ILOGBNAN } else { i32::max_value() }
24+
if (i << 9) != 0 { FP_ILOGBNAN } else { i32::MAX }
2525
} else {
2626
e - 0x7f
2727
}

0 commit comments

Comments
 (0)