cleanup
This commit is contained in:
25
src/lib.rs
25
src/lib.rs
@@ -1,4 +1,4 @@
|
|||||||
#![no_std]
|
// #![no_std]
|
||||||
|
|
||||||
use core::{error::Error, fmt::Display};
|
use core::{error::Error, fmt::Display};
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
@@ -95,13 +95,13 @@ impl<const S: usize, E: PrimInt + Unsigned> TryFrom<Decimal<S, E>> for f64 {
|
|||||||
exponent,
|
exponent,
|
||||||
} = val;
|
} = val;
|
||||||
|
|
||||||
let mut f: f64 = 0.0;
|
let mut e = exponent.to_i32().ok_or(DecimalError::ExponentOverflow)?;
|
||||||
|
if minus_exponent {
|
||||||
|
e = -e;
|
||||||
|
}
|
||||||
|
let e = 10.0f64.powi(e);
|
||||||
|
|
||||||
let e = if minus_exponent {
|
let mut f: f64 = 0.0;
|
||||||
10.0f64.powi(-exponent.to_i32().ok_or(DecimalError::ExponentOverflow)?)
|
|
||||||
} else {
|
|
||||||
10.0f64.powi(exponent.to_i32().ok_or(DecimalError::ExponentOverflow)?)
|
|
||||||
};
|
|
||||||
|
|
||||||
for i in (0..S).rev() {
|
for i in (0..S).rev() {
|
||||||
f /= 10.0;
|
f /= 10.0;
|
||||||
@@ -253,9 +253,10 @@ mod tests {
|
|||||||
assert_eq!(f64::try_from(dec).unwrap(), -0.0133742);
|
assert_eq!(f64::try_from(dec).unwrap(), -0.0133742);
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn decimal_to_float_max() {
|
#[ignore = "not working due to precission issues"]
|
||||||
// let dec = Decimal::<16>::try_from(f64::MAX / 2.0).unwrap();
|
fn decimal_to_float_max() {
|
||||||
// assert_eq!(f64::try_from(dec).unwrap(), f64::MAX / 2.0);
|
let dec = Decimal::<16>::try_from(f64::MAX).unwrap();
|
||||||
// }
|
assert_eq!(f64::try_from(dec).unwrap(), f64::MAX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user