Fix Duration::{try_,}from_secs_f{32,64}(-0.0)

This commit is contained in:
beetrees 2022-10-14 15:51:20 +01:00
parent 9b0a099dfc
commit c9948f5c5f
No known key found for this signature in database
GPG Key ID: 8791BD754191EBD6
3 changed files with 10 additions and 1 deletions

View File

@ -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 });
}

View File

@ -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;

View File

@ -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);
}