From 2c300fa15b65e75ca07ada06819502ced7d80882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Mon, 30 Jul 2018 12:12:52 +0300 Subject: [PATCH] change negativity check --- src/libcore/time.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 4777b4356376..cd98f51f5cdb 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -517,16 +517,16 @@ impl Mul for Duration { fn mul(self, rhs: f64) -> Duration { const NPS: f64 = NANOS_PER_SEC as f64; - if rhs.is_sign_negative() { - panic!("duration can not be multiplied by negative float"); - } let nanos_f64 = rhs * (NPS * (self.secs as f64) + (self.nanos as f64)); if !nanos_f64.is_finite() { panic!("got non-finite value when multiplying duration by float"); } if nanos_f64 > MAX_NANOS_F64 { panic!("overflow when multiplying duration by float"); - }; + } + if nanos_f64 < 0.0 { + panic!("underflow when multiplying duration by float"); + } let nanos_u128 = nanos_f64 as u128; Duration { secs: (nanos_u128 / (NANOS_PER_SEC as u128)) as u64, @@ -541,16 +541,16 @@ impl Mul for f64 { fn mul(self, rhs: Duration) -> Duration { const NPS: f64 = NANOS_PER_SEC as f64; - if self.is_sign_negative() { - panic!("duration can not be multiplied by negative float"); - } let nanos_f64 = self * (NPS * (rhs.secs as f64) + (rhs.nanos as f64)); if !nanos_f64.is_finite() { panic!("got non-finite value when multiplying float by duration"); } if nanos_f64 > MAX_NANOS_F64 { panic!("overflow when multiplying float by duration"); - }; + } + if nanos_f64 < 0.0 { + panic!("underflow when multiplying float by duration"); + } let nanos_u128 = nanos_f64 as u128; Duration { secs: (nanos_u128 / (NANOS_PER_SEC as u128)) as u64, @@ -588,16 +588,16 @@ impl Div for Duration { fn div(self, rhs: f64) -> Duration { const NPS: f64 = NANOS_PER_SEC as f64; - if rhs.is_sign_negative() { - panic!("duration can not be divided by negative float"); - } let nanos_f64 = (NPS * (self.secs as f64) + (self.nanos as f64)) / rhs; if !nanos_f64.is_finite() { panic!("got non-finite value when dividing duration by float"); } if nanos_f64 > MAX_NANOS_F64 { panic!("overflow when dividing duration by float"); - }; + } + if nanos_f64 < 0.0 { + panic!("underflow when multiplying duration by float"); + } let nanos_u128 = nanos_f64 as u128; Duration { secs: (nanos_u128 / (NANOS_PER_SEC as u128)) as u64,