diff --git a/src/lib.rs b/src/lib.rs index 6f6a554..f6364c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +// #![no_std] use core::{error::Error, fmt::Display}; #[cfg(not(test))] @@ -95,13 +95,13 @@ impl TryFrom> for f64 { exponent, } = 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 { - 10.0f64.powi(-exponent.to_i32().ok_or(DecimalError::ExponentOverflow)?) - } else { - 10.0f64.powi(exponent.to_i32().ok_or(DecimalError::ExponentOverflow)?) - }; + let mut f: f64 = 0.0; for i in (0..S).rev() { f /= 10.0; @@ -253,9 +253,10 @@ mod tests { assert_eq!(f64::try_from(dec).unwrap(), -0.0133742); } - // #[test] - // fn decimal_to_float_max() { - // let dec = Decimal::<16>::try_from(f64::MAX / 2.0).unwrap(); - // assert_eq!(f64::try_from(dec).unwrap(), f64::MAX / 2.0); - // } + #[test] + #[ignore = "not working due to precission issues"] + fn decimal_to_float_max() { + let dec = Decimal::<16>::try_from(f64::MAX).unwrap(); + assert_eq!(f64::try_from(dec).unwrap(), f64::MAX); + } }