Skip to content

Commit

Permalink
Fix Duration::{try_,}from_secs_f{32,64}(-0.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
beetrees committed Oct 14, 2022
1 parent 9b0a099 commit c9948f5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ macro_rules! try_from_secs {
const MANT_MASK: $bits_ty = (1 << $mant_bits) - 1;
const EXP_MASK: $bits_ty = (1 << $exp_bits) - 1;

if $secs.is_sign_negative() {
if $secs < 0.0 {
return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::Negative });
}

Expand Down
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
#![feature(provide_any)]
#![feature(utf8_chunks)]
#![feature(is_ascii_octdigit)]
#![feature(duration_checked_float)]
#![deny(unsafe_op_in_unsafe_fn)]

extern crate test;
Expand Down
8 changes: 8 additions & 0 deletions library/core/tests/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,11 @@ fn duration_const() {
const SATURATING_MUL: Duration = MAX.saturating_mul(2);
assert_eq!(SATURATING_MUL, MAX);
}

#[test]
fn from_neg_zero() {
assert_eq!(Duration::try_from_secs_f32(-0.0), Ok(Duration::ZERO));
assert_eq!(Duration::try_from_secs_f64(-0.0), Ok(Duration::ZERO));
assert_eq!(Duration::from_secs_f32(-0.0), Duration::ZERO);
assert_eq!(Duration::from_secs_f64(-0.0), Duration::ZERO);
}

0 comments on commit c9948f5

Please sign in to comment.