fix time convert overflow checks
This commit is contained in:
@@ -20,13 +20,14 @@ pub fn from_float<T>(time:f64)->Result<Time<T>,Error>{
|
||||
core::num::FpCategory::Infinite
|
||||
|core::num::FpCategory::Subnormal
|
||||
|core::num::FpCategory::Normal=>{
|
||||
if time<Time::<T>::MIN.get() as f64{
|
||||
let time_raw=time*Time::<T>::ONE_SECOND.get() as f64;
|
||||
if time_raw<Time::<T>::MIN.get() as f64{
|
||||
return Err(Error::Underflow);
|
||||
}
|
||||
if (Time::<T>::MAX.get() as f64)<time{
|
||||
if (Time::<T>::MAX.get() as f64)<time_raw{
|
||||
return Err(Error::Overflow);
|
||||
}
|
||||
Ok(Time::raw((time*Time::<T>::ONE_SECOND.get() as f64) as i64))
|
||||
Ok(Time::raw(time_raw as i64))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user