Skip to content

Commit 4cd303d

Browse files
committed
Resolve clippy errors in libm tests and check this in CI
1 parent af009cc commit 4cd303d

File tree

10 files changed

+65
-83
lines changed

10 files changed

+65
-83
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ jobs:
106106
cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
107107
108108
- name: Clippy
109-
run: |
109+
# Tests and utilities can't build on no_std targets
110+
if: "!contains(matrix.target, 'thumb')"
110111
# Run clippy on `libm`
111-
cargo clippy --target "${{ matrix.target }}" --package libm
112+
run: cargo clippy --target "${{ matrix.target }}" --package libm --all-targets
112113

113114

114115
builtins:

src/math/ceil.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ pub fn ceil(x: f64) -> f64 {
3434

3535
#[cfg(test)]
3636
mod tests {
37-
use core::f64::*;
38-
3937
use super::*;
4038

4139
#[test]
@@ -48,8 +46,8 @@ mod tests {
4846
#[test]
4947
fn spec_tests() {
5048
// Not Asserted: that the current rounding mode has no effect.
51-
assert!(ceil(NAN).is_nan());
52-
for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
49+
assert!(ceil(f64::NAN).is_nan());
50+
for f in [0.0, -0.0, f64::INFINITY, f64::NEG_INFINITY].iter().copied() {
5351
assert_eq!(ceil(f), f);
5452
}
5553
}

src/math/ceilf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub fn ceilf(x: f32) -> f32 {
4242
#[cfg(not(target_arch = "powerpc64"))]
4343
#[cfg(test)]
4444
mod tests {
45-
use core::f32::*;
46-
4745
use super::*;
4846

4947
#[test]
@@ -56,8 +54,8 @@ mod tests {
5654
#[test]
5755
fn spec_tests() {
5856
// Not Asserted: that the current rounding mode has no effect.
59-
assert!(ceilf(NAN).is_nan());
60-
for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
57+
assert!(ceilf(f32::NAN).is_nan());
58+
for f in [0.0, -0.0, f32::INFINITY, f32::NEG_INFINITY].iter().copied() {
6159
assert_eq!(ceilf(f), f);
6260
}
6361
}

src/math/fabs.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub fn fabs(x: f64) -> f64 {
1414

1515
#[cfg(test)]
1616
mod tests {
17-
use core::f64::*;
18-
1917
use super::*;
2018

2119
#[test]
@@ -27,12 +25,12 @@ mod tests {
2725
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs
2826
#[test]
2927
fn spec_tests() {
30-
assert!(fabs(NAN).is_nan());
28+
assert!(fabs(f64::NAN).is_nan());
3129
for f in [0.0, -0.0].iter().copied() {
3230
assert_eq!(fabs(f), 0.0);
3331
}
34-
for f in [INFINITY, NEG_INFINITY].iter().copied() {
35-
assert_eq!(fabs(f), INFINITY);
32+
for f in [f64::INFINITY, f64::NEG_INFINITY].iter().copied() {
33+
assert_eq!(fabs(f), f64::INFINITY);
3634
}
3735
}
3836
}

src/math/fabsf.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub fn fabsf(x: f32) -> f32 {
1616
#[cfg(not(target_arch = "powerpc64"))]
1717
#[cfg(test)]
1818
mod tests {
19-
use core::f32::*;
20-
2119
use super::*;
2220

2321
#[test]
@@ -29,12 +27,12 @@ mod tests {
2927
/// The spec: https://en.cppreference.com/w/cpp/numeric/math/fabs
3028
#[test]
3129
fn spec_tests() {
32-
assert!(fabsf(NAN).is_nan());
30+
assert!(fabsf(f32::NAN).is_nan());
3331
for f in [0.0, -0.0].iter().copied() {
3432
assert_eq!(fabsf(f), 0.0);
3533
}
36-
for f in [INFINITY, NEG_INFINITY].iter().copied() {
37-
assert_eq!(fabsf(f), INFINITY);
34+
for f in [f32::INFINITY, f32::NEG_INFINITY].iter().copied() {
35+
assert_eq!(fabsf(f), f32::INFINITY);
3836
}
3937
}
4038
}

src/math/floor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub fn floor(x: f64) -> f64 {
3333

3434
#[cfg(test)]
3535
mod tests {
36-
use core::f64::*;
37-
3836
use super::*;
3937

4038
#[test]
@@ -47,8 +45,8 @@ mod tests {
4745
#[test]
4846
fn spec_tests() {
4947
// Not Asserted: that the current rounding mode has no effect.
50-
assert!(floor(NAN).is_nan());
51-
for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
48+
assert!(floor(f64::NAN).is_nan());
49+
for f in [0.0, -0.0, f64::INFINITY, f64::NEG_INFINITY].iter().copied() {
5250
assert_eq!(floor(f), f);
5351
}
5452
}

src/math/floorf.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ pub fn floorf(x: f32) -> f32 {
4242
#[cfg(not(target_arch = "powerpc64"))]
4343
#[cfg(test)]
4444
mod tests {
45-
use core::f32::*;
46-
4745
use super::*;
4846

4947
#[test]
@@ -57,8 +55,8 @@ mod tests {
5755
#[test]
5856
fn spec_tests() {
5957
// Not Asserted: that the current rounding mode has no effect.
60-
assert!(floorf(NAN).is_nan());
61-
for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
58+
assert!(floorf(f32::NAN).is_nan());
59+
for f in [0.0, -0.0, f32::INFINITY, f32::NEG_INFINITY].iter().copied() {
6260
assert_eq!(floorf(f), f);
6361
}
6462
}

src/math/pow.rs

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ mod tests {
398398
extern crate core;
399399

400400
use self::core::f64::consts::{E, PI};
401-
use self::core::f64::{EPSILON, INFINITY, MAX, MIN, MIN_POSITIVE, NAN, NEG_INFINITY};
402401
use super::pow;
403402

404403
const POS_ZERO: &[f64] = &[0.0];
@@ -407,15 +406,15 @@ mod tests {
407406
const NEG_ONE: &[f64] = &[-1.0];
408407
const POS_FLOATS: &[f64] = &[99.0 / 70.0, E, PI];
409408
const NEG_FLOATS: &[f64] = &[-99.0 / 70.0, -E, -PI];
410-
const POS_SMALL_FLOATS: &[f64] = &[(1.0 / 2.0), MIN_POSITIVE, EPSILON];
411-
const NEG_SMALL_FLOATS: &[f64] = &[-(1.0 / 2.0), -MIN_POSITIVE, -EPSILON];
412-
const POS_EVENS: &[f64] = &[2.0, 6.0, 8.0, 10.0, 22.0, 100.0, MAX];
413-
const NEG_EVENS: &[f64] = &[MIN, -100.0, -22.0, -10.0, -8.0, -6.0, -2.0];
409+
const POS_SMALL_FLOATS: &[f64] = &[(1.0 / 2.0), f64::MIN_POSITIVE, f64::EPSILON];
410+
const NEG_SMALL_FLOATS: &[f64] = &[-(1.0 / 2.0), -f64::MIN_POSITIVE, -f64::EPSILON];
411+
const POS_EVENS: &[f64] = &[2.0, 6.0, 8.0, 10.0, 22.0, 100.0, f64::MAX];
412+
const NEG_EVENS: &[f64] = &[f64::MIN, -100.0, -22.0, -10.0, -8.0, -6.0, -2.0];
414413
const POS_ODDS: &[f64] = &[3.0, 7.0];
415414
const NEG_ODDS: &[f64] = &[-7.0, -3.0];
416-
const NANS: &[f64] = &[NAN];
417-
const POS_INF: &[f64] = &[INFINITY];
418-
const NEG_INF: &[f64] = &[NEG_INFINITY];
415+
const NANS: &[f64] = &[f64::NAN];
416+
const POS_INF: &[f64] = &[f64::INFINITY];
417+
const NEG_INF: &[f64] = &[f64::NEG_INFINITY];
419418

420419
const ALL: &[&[f64]] = &[
421420
POS_ZERO,
@@ -492,83 +491,83 @@ mod tests {
492491
#[test]
493492
fn nan_inputs() {
494493
// NAN as the base:
495-
// (NAN ^ anything *but 0* should be NAN)
496-
test_sets_as_exponent(NAN, &ALL[2..], NAN);
494+
// (f64::NAN ^ anything *but 0* should be f64::NAN)
495+
test_sets_as_exponent(f64::NAN, &ALL[2..], f64::NAN);
497496

498-
// NAN as the exponent:
499-
// (anything *but 1* ^ NAN should be NAN)
500-
test_sets_as_base(&ALL[..(ALL.len() - 2)], NAN, NAN);
497+
// f64::NAN as the exponent:
498+
// (anything *but 1* ^ f64::NAN should be f64::NAN)
499+
test_sets_as_base(&ALL[..(ALL.len() - 2)], f64::NAN, f64::NAN);
501500
}
502501

503502
#[test]
504503
fn infinity_as_base() {
505504
// Positive Infinity as the base:
506-
// (+Infinity ^ positive anything but 0 and NAN should be +Infinity)
507-
test_sets_as_exponent(INFINITY, &POS[1..], INFINITY);
505+
// (+Infinity ^ positive anything but 0 and f64::NAN should be +Infinity)
506+
test_sets_as_exponent(f64::INFINITY, &POS[1..], f64::INFINITY);
508507

509-
// (+Infinity ^ negative anything except 0 and NAN should be 0.0)
510-
test_sets_as_exponent(INFINITY, &NEG[1..], 0.0);
508+
// (+Infinity ^ negative anything except 0 and f64::NAN should be 0.0)
509+
test_sets_as_exponent(f64::INFINITY, &NEG[1..], 0.0);
511510

512511
// Negative Infinity as the base:
513512
// (-Infinity ^ positive odd ints should be -Infinity)
514-
test_sets_as_exponent(NEG_INFINITY, &[POS_ODDS], NEG_INFINITY);
513+
test_sets_as_exponent(f64::NEG_INFINITY, &[POS_ODDS], f64::NEG_INFINITY);
515514

516515
// (-Infinity ^ anything but odd ints should be == -0 ^ (-anything))
517516
// We can lump in pos/neg odd ints here because they don't seem to
518517
// cause panics (div by zero) in release mode (I think).
519-
test_sets(ALL, &|v: f64| pow(NEG_INFINITY, v), &|v: f64| pow(-0.0, -v));
518+
test_sets(ALL, &|v: f64| pow(f64::NEG_INFINITY, v), &|v: f64| pow(-0.0, -v));
520519
}
521520

522521
#[test]
523522
fn infinity_as_exponent() {
524523
// Positive/Negative base greater than 1:
525-
// (pos/neg > 1 ^ Infinity should be Infinity - note this excludes NAN as the base)
526-
test_sets_as_base(&ALL[5..(ALL.len() - 2)], INFINITY, INFINITY);
524+
// (pos/neg > 1 ^ Infinity should be Infinity - note this excludes f64::NAN as the base)
525+
test_sets_as_base(&ALL[5..(ALL.len() - 2)], f64::INFINITY, f64::INFINITY);
527526

528527
// (pos/neg > 1 ^ -Infinity should be 0.0)
529-
test_sets_as_base(&ALL[5..ALL.len() - 2], NEG_INFINITY, 0.0);
528+
test_sets_as_base(&ALL[5..ALL.len() - 2], f64::NEG_INFINITY, 0.0);
530529

531530
// Positive/Negative base less than 1:
532531
let base_below_one = &[POS_ZERO, NEG_ZERO, NEG_SMALL_FLOATS, POS_SMALL_FLOATS];
533532

534-
// (pos/neg < 1 ^ Infinity should be 0.0 - this also excludes NAN as the base)
535-
test_sets_as_base(base_below_one, INFINITY, 0.0);
533+
// (pos/neg < 1 ^ Infinity should be 0.0 - this also excludes f64::NAN as the base)
534+
test_sets_as_base(base_below_one, f64::INFINITY, 0.0);
536535

537536
// (pos/neg < 1 ^ -Infinity should be Infinity)
538-
test_sets_as_base(base_below_one, NEG_INFINITY, INFINITY);
537+
test_sets_as_base(base_below_one, f64::NEG_INFINITY, f64::INFINITY);
539538

540539
// Positive/Negative 1 as the base:
541540
// (pos/neg 1 ^ Infinity should be 1)
542-
test_sets_as_base(&[NEG_ONE, POS_ONE], INFINITY, 1.0);
541+
test_sets_as_base(&[NEG_ONE, POS_ONE], f64::INFINITY, 1.0);
543542

544543
// (pos/neg 1 ^ -Infinity should be 1)
545-
test_sets_as_base(&[NEG_ONE, POS_ONE], NEG_INFINITY, 1.0);
544+
test_sets_as_base(&[NEG_ONE, POS_ONE], f64::NEG_INFINITY, 1.0);
546545
}
547546

548547
#[test]
549548
fn zero_as_base() {
550549
// Positive Zero as the base:
551-
// (+0 ^ anything positive but 0 and NAN should be +0)
550+
// (+0 ^ anything positive but 0 and f64::NAN should be +0)
552551
test_sets_as_exponent(0.0, &POS[1..], 0.0);
553552

554-
// (+0 ^ anything negative but 0 and NAN should be Infinity)
553+
// (+0 ^ anything negative but 0 and f64::NAN should be Infinity)
555554
// (this should panic because we're dividing by zero)
556-
test_sets_as_exponent(0.0, &NEG[1..], INFINITY);
555+
test_sets_as_exponent(0.0, &NEG[1..], f64::INFINITY);
557556

558557
// Negative Zero as the base:
559-
// (-0 ^ anything positive but 0, NAN, and odd ints should be +0)
558+
// (-0 ^ anything positive but 0, f64::NAN, and odd ints should be +0)
560559
test_sets_as_exponent(-0.0, &POS[3..], 0.0);
561560

562-
// (-0 ^ anything negative but 0, NAN, and odd ints should be Infinity)
561+
// (-0 ^ anything negative but 0, f64::NAN, and odd ints should be Infinity)
563562
// (should panic because of divide by zero)
564-
test_sets_as_exponent(-0.0, &NEG[3..], INFINITY);
563+
test_sets_as_exponent(-0.0, &NEG[3..], f64::INFINITY);
565564

566565
// (-0 ^ positive odd ints should be -0)
567566
test_sets_as_exponent(-0.0, &[POS_ODDS], -0.0);
568567

569568
// (-0 ^ negative odd ints should be -Infinity)
570569
// (should panic because of divide by zero)
571-
test_sets_as_exponent(-0.0, &[NEG_ODDS], NEG_INFINITY);
570+
test_sets_as_exponent(-0.0, &[NEG_ODDS], f64::NEG_INFINITY);
572571
}
573572

574573
#[test]
@@ -583,21 +582,17 @@ mod tests {
583582

584583
// Factoring -1 out:
585584
// (negative anything ^ integer should be (-1 ^ integer) * (positive anything ^ integer))
586-
(&[POS_ZERO, NEG_ZERO, POS_ONE, NEG_ONE, POS_EVENS, NEG_EVENS]).iter().for_each(
587-
|int_set| {
588-
int_set.iter().for_each(|int| {
589-
test_sets(ALL, &|v: f64| pow(-v, *int), &|v: f64| {
590-
pow(-1.0, *int) * pow(v, *int)
591-
});
592-
})
593-
},
594-
);
585+
[POS_ZERO, NEG_ZERO, POS_ONE, NEG_ONE, POS_EVENS, NEG_EVENS].iter().for_each(|int_set| {
586+
int_set.iter().for_each(|int| {
587+
test_sets(ALL, &|v: f64| pow(-v, *int), &|v: f64| pow(-1.0, *int) * pow(v, *int));
588+
})
589+
});
595590

596591
// Negative base (imaginary results):
597592
// (-anything except 0 and Infinity ^ non-integer should be NAN)
598-
(&NEG[1..(NEG.len() - 1)]).iter().for_each(|set| {
593+
NEG[1..(NEG.len() - 1)].iter().for_each(|set| {
599594
set.iter().for_each(|val| {
600-
test_sets(&ALL[3..7], &|v: f64| pow(*val, v), &|_| NAN);
595+
test_sets(&ALL[3..7], &|v: f64| pow(*val, v), &|_| f64::NAN);
601596
})
602597
});
603598
}

src/math/sqrt.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ pub fn sqrt(x: f64) -> f64 {
224224

225225
#[cfg(test)]
226226
mod tests {
227-
use core::f64::*;
228-
229227
use super::*;
230228

231229
#[test]
@@ -239,15 +237,16 @@ mod tests {
239237
fn spec_tests() {
240238
// Not Asserted: FE_INVALID exception is raised if argument is negative.
241239
assert!(sqrt(-1.0).is_nan());
242-
assert!(sqrt(NAN).is_nan());
243-
for f in [0.0, -0.0, INFINITY].iter().copied() {
240+
assert!(sqrt(f64::NAN).is_nan());
241+
for f in [0.0, -0.0, f64::INFINITY].iter().copied() {
244242
assert_eq!(sqrt(f), f);
245243
}
246244
}
247245

248246
#[test]
247+
#[allow(clippy::approx_constant)]
249248
fn conformance_tests() {
250-
let values = [3.14159265359, 10000.0, f64::from_bits(0x0000000f), INFINITY];
249+
let values = [3.14159265359, 10000.0, f64::from_bits(0x0000000f), f64::INFINITY];
251250
let results = [
252251
4610661241675116657u64,
253252
4636737291354636288u64,

src/math/sqrtf.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ pub fn sqrtf(x: f32) -> f32 {
110110
#[cfg(not(target_arch = "powerpc64"))]
111111
#[cfg(test)]
112112
mod tests {
113-
use core::f32::*;
114-
115113
use super::*;
116114

117115
#[test]
@@ -125,15 +123,16 @@ mod tests {
125123
fn spec_tests() {
126124
// Not Asserted: FE_INVALID exception is raised if argument is negative.
127125
assert!(sqrtf(-1.0).is_nan());
128-
assert!(sqrtf(NAN).is_nan());
129-
for f in [0.0, -0.0, INFINITY].iter().copied() {
126+
assert!(sqrtf(f32::NAN).is_nan());
127+
for f in [0.0, -0.0, f32::INFINITY].iter().copied() {
130128
assert_eq!(sqrtf(f), f);
131129
}
132130
}
133131

134132
#[test]
133+
#[allow(clippy::approx_constant)]
135134
fn conformance_tests() {
136-
let values = [3.14159265359f32, 10000.0f32, f32::from_bits(0x0000000f), INFINITY];
135+
let values = [3.14159265359f32, 10000.0f32, f32::from_bits(0x0000000f), f32::INFINITY];
137136
let results = [1071833029u32, 1120403456u32, 456082799u32, 2139095040u32];
138137

139138
for i in 0..values.len() {

0 commit comments

Comments
 (0)