change negativity check
This commit is contained in:
parent
3e07236a31
commit
2c300fa15b
1 changed files with 12 additions and 12 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue