Skip to content

Commit

Permalink
Replace legacy numeric constants with associated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld committed Jun 20, 2024
1 parent 79a6f38 commit e356a09
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ntp-proto/src/time_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ impl NtpDuration {

// Ensure proper saturating behaviour
let duration = match i as i64 {
i if i >= std::i32::MIN as i64 && i <= std::i32::MAX as i64 => {
i if i >= i32::MIN as i64 && i <= i32::MAX as i64 => {
(i << 32) | (f * u32::MAX as f64) as i64
}
i if i < std::i32::MIN as i64 => std::i64::MIN,
i if i > std::i32::MAX as i64 => std::i64::MAX,
i if i < i32::MIN as i64 => i64::MIN,
i if i > i32::MAX as i64 => i64::MAX,
_ => unreachable!(),
};

Expand Down Expand Up @@ -310,7 +310,7 @@ impl NtpDuration {
pub const fn from_exponent(input: i8) -> Self {
Self {
duration: match input {
exp if exp > 30 => std::i64::MAX,
exp if exp > 30 => i64::MAX,
exp if exp > 0 && exp <= 30 => 0x1_0000_0000_i64 << exp,
exp if exp >= -32 && exp <= 0 => 0x1_0000_0000_i64 >> -exp,
_ => 0,
Expand Down Expand Up @@ -803,11 +803,11 @@ mod tests {
fn duration_from_float_seconds_saturates() {
assert_eq!(
NtpDuration::from_seconds(1e40),
NtpDuration::from_fixed_int(std::i64::MAX)
NtpDuration::from_fixed_int(i64::MAX)
);
assert_eq!(
NtpDuration::from_seconds(-1e40),
NtpDuration::from_fixed_int(std::i64::MIN)
NtpDuration::from_fixed_int(i64::MIN)
);
}

Expand Down

0 comments on commit e356a09

Please sign in to comment.