Skip to content

Commit

Permalink
chore: fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 16, 2023
1 parent 979f548 commit 770a0bf
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 29 deletions.
28 changes: 16 additions & 12 deletions apfloat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,24 @@ use core::str::FromStr;

use amplify_num::{i256, u256};

bitflags! {
/// IEEE-754R 7: Default exception handling.
///
/// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
#[must_use]
pub struct Status: u8 {
const OK = 0x00;
const INVALID_OP = 0x01;
const DIV_BY_ZERO = 0x02;
const OVERFLOW = 0x04;
const UNDERFLOW = 0x08;
const INEXACT = 0x10;
mod status {
#![allow(clippy::bad_bit_mask)]
bitflags! {
/// IEEE-754R 7: Default exception handling.
///
/// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
#[must_use]
pub struct Status: u8 {
const OK = 0x00;
const INVALID_OP = 0x01;
const DIV_BY_ZERO = 0x02;
const OVERFLOW = 0x04;
const UNDERFLOW = 0x08;
const INEXACT = 0x10;
}
}
}
pub use status::Status;

#[must_use]
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
Expand Down
21 changes: 14 additions & 7 deletions apfloat/tests/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ fn next() {
}

#[test]
#[allow(clippy::excessive_precision)]
fn fma() {
{
let mut f1 = Single::from_f32(14.5);
Expand Down Expand Up @@ -707,7 +708,7 @@ fn decimal_strings_without_null_terminators() {

#[test]
fn oct_decimal_string() {
assert_eq!(true, "0".parse::<Oct>().unwrap().is_zero());
assert!("0".parse::<Oct>().unwrap().is_zero());
assert_eq!("0.5", "0.5".parse::<Oct>().unwrap().to_string());
}

Expand Down Expand Up @@ -878,6 +879,7 @@ fn from_zero_hexadecimal_string() {
}

#[test]
#[allow(clippy::approx_constant)]
fn from_decimal_string() {
assert_eq!(1.0, "1".parse::<Double>().unwrap().to_f64());
assert_eq!(2.0, "2.".parse::<Double>().unwrap().to_f64());
Expand Down Expand Up @@ -1008,6 +1010,7 @@ fn from_hexadecimal_string() {
}

#[test]
#[allow(clippy::excessive_precision)]
fn to_string() {
let to_string = |d: f64, precision: usize, width: usize| {
let x = Double::from_f64(d);
Expand Down Expand Up @@ -1173,11 +1176,11 @@ fn string_decimal_death() {

assert_eq!("\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1\02".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1\02e1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1\x002".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1\x002e1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("1e\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("1e1\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("1e1\02".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("1e1\x002".parse::<Double>(), Err(ParseError("Invalid character in exponent")));

assert_eq!("1.0f".parse::<Double>(), Err(ParseError("Invalid character in significand")));

Expand Down Expand Up @@ -1263,11 +1266,11 @@ fn string_hexadecimal_death() {

assert_eq!("0x\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1\0".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1\02".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1\02p1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1\x002".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1\x002p1".parse::<Double>(), Err(ParseError("Invalid character in significand")));
assert_eq!("0x1p\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("0x1p1\0".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("0x1p1\02".parse::<Double>(), Err(ParseError("Invalid character in exponent")));
assert_eq!("0x1p1\x002".parse::<Double>(), Err(ParseError("Invalid character in exponent")));

assert_eq!("0x1p0f".parse::<Double>(), Err(ParseError("Invalid character in exponent")));

Expand Down Expand Up @@ -1359,6 +1362,7 @@ fn string_hexadecimal_exponent_death() {
}

#[test]
#[allow(clippy::excessive_precision)]
fn exact_inverse() {
// Trivial operation.
assert!(
Expand Down Expand Up @@ -1411,6 +1415,7 @@ fn exact_inverse() {
}

#[test]
#[allow(clippy::approx_constant)]
fn round_to_integral() {
let t = Double::from_f64(-0.5);
assert_eq!(-0.0, t.round_to_integral(Round::TowardZero).value.to_f64());
Expand Down Expand Up @@ -1445,6 +1450,7 @@ fn round_to_integral() {
}

#[test]
#[allow(clippy::approx_constant)]
fn is_integer() {
let t = Double::from_f64(-0.0);
assert!(t.is_integer());
Expand All @@ -1461,6 +1467,7 @@ fn is_integer() {
}

#[test]
#[allow(clippy::excessive_precision)]
fn largest() {
assert_eq!(3.402823466e+38, Single::largest().to_f32());
assert_eq!(1.7976931348623158e+308, Double::largest().to_f64());
Expand Down
18 changes: 9 additions & 9 deletions num/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,11 +1488,11 @@ mod tests {

// Try to read the following lines out loud quickly
let mut shl = u256::from(70000u64);
shl = shl << 100;
shl <<= 100;
assert_eq!(shl.bits_required(), 117);
shl = shl << 100;
shl <<= 100;
assert_eq!(shl.bits_required(), 217);
shl = shl << 100;
shl <<= 100;
assert_eq!(shl.bits_required(), 0);

// Bit set check
Expand Down Expand Up @@ -1920,12 +1920,12 @@ mod tests {

#[test]
fn i256_is_positive_test() {
assert_eq!(true, i256::from(1).is_positive());
assert_eq!(false, i256::from(-1).is_positive());
assert_eq!(false, i256::from(0).is_positive());
assert_eq!(true, i256::MAX.is_positive());
assert_eq!(false, i256::MIN.is_positive());
assert_eq!(true, i256::MIN.is_negative());
assert!(i256::from(1).is_positive());
assert!(!i256::from(-1).is_positive());
assert!(!i256::from(0).is_positive());
assert!(i256::MAX.is_positive());
assert!(!i256::MIN.is_positive());
assert!(i256::MIN.is_negative());
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions num/src/posit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ mod tests {
}

#[test]
#[allow(clippy::nonminimal_bool)]
fn posit_cmp_test() {
assert!(Posit16::from(4.) < Posit16::from(5.));
assert!(Posit16::from(0.) <= (Posit16::from(0.)));
Expand Down
5 changes: 4 additions & 1 deletion num/src/smallint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ macro_rules! construct_smallint {
/// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at
/// the boundary of the type.
pub fn wrapping_add<T>(self, rhs: T) -> Self where T: Into<$inner> {
#[allow(clippy::modulo_one)]
Self(self.0.wrapping_add(rhs.into()) % Self::MAX.0)
}

Expand Down Expand Up @@ -204,6 +205,7 @@ macro_rules! construct_smallint {
/// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at
/// the boundary of the type.
pub fn wrapping_sub<T>(self, rhs: T) -> Self where T: Into<$inner> {
#[allow(clippy::modulo_one)]
Self(self.0.wrapping_sub(rhs.into()) % Self::MAX.0)
}

Expand Down Expand Up @@ -238,6 +240,7 @@ macro_rules! construct_smallint {
/// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at
/// the boundary of the type.
pub fn wrapping_mul<T>(self, rhs: T) -> Self where T: Into<$inner> {
#[allow(clippy::modulo_one)]
Self(self.0.wrapping_mul(rhs.into()) % Self::MAX.0)
}

Expand Down Expand Up @@ -598,7 +601,7 @@ mod test {
fn smallint_div_rem_0() {
let u_2 = u2::MAX;
let u_2_2 = u2::try_from(2).unwrap();
let u_2_half = (u2::try_from(u2::MAX / 2).unwrap(), u2::try_from(u2::MAX % 2).unwrap());
let u_2_half = (u2::MAX / 2, u2::MAX % 2);
let u_2_zero = u2::ZERO;

assert_eq!(u2::div_rem(u_2, u_2_2), Ok(u_2_half));
Expand Down

0 comments on commit 770a0bf

Please sign in to comment.