Rollup merge of #103059 - beetrees:duration-from-negative-zero, r=thomcc
Fix `Duration::{try_,}from_secs_f{32,64}(-0.0)` Make `Duration::{try_,}from_secs_f{32,64}(-0.0)` return `Duration::ZERO` (as they did before #90247) instead of erroring/panicking. I'll update this PR to remove the `#![feature(duration_checked_float)]` if #102271 is merged before this PR. Tracking issue for `try_from_secs_f{32,64}`: #83400
This commit is contained in:
commit
03a521b4fe
3 changed files with 10 additions and 1 deletions
|
@ -1279,7 +1279,7 @@ macro_rules! try_from_secs {
|
||||||
const MANT_MASK: $bits_ty = (1 << $mant_bits) - 1;
|
const MANT_MASK: $bits_ty = (1 << $mant_bits) - 1;
|
||||||
const EXP_MASK: $bits_ty = (1 << $exp_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 });
|
return Err(FromFloatSecsError { kind: FromFloatSecsErrorKind::Negative });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
#![feature(provide_any)]
|
#![feature(provide_any)]
|
||||||
#![feature(utf8_chunks)]
|
#![feature(utf8_chunks)]
|
||||||
#![feature(is_ascii_octdigit)]
|
#![feature(is_ascii_octdigit)]
|
||||||
|
#![feature(duration_checked_float)]
|
||||||
#![deny(unsafe_op_in_unsafe_fn)]
|
#![deny(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
|
|
@ -467,3 +467,11 @@ fn duration_const() {
|
||||||
const SATURATING_MUL: Duration = MAX.saturating_mul(2);
|
const SATURATING_MUL: Duration = MAX.saturating_mul(2);
|
||||||
assert_eq!(SATURATING_MUL, MAX);
|
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);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue