diff options
| author | Артём Павлов [Artyom Pavlov] <newpavlov@gmail.com> | 2018-07-30 12:12:52 +0300 |
|---|---|---|
| committer | Артём Павлов [Artyom Pavlov] <newpavlov@gmail.com> | 2018-07-30 12:12:52 +0300 |
| commit | 2c300fa15b65e75ca07ada06819502ced7d80882 (patch) | |
| tree | 66e2a410f89c2169189875ab391faadf66b445d0 /src/libcore | |
| parent | 3e07236a31950aa8e6a4c66066de02d1bca68ea9 (diff) | |
| download | rust-2c300fa15b65e75ca07ada06819502ced7d80882.tar.gz rust-2c300fa15b65e75ca07ada06819502ced7d80882.zip | |
change negativity check
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/time.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 4777b435637..cd98f51f5cd 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -517,16 +517,16 @@ impl Mul<f64> 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<Duration> 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<f64> 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, |
