This commit is contained in:
2025-07-18 21:19:30 +01:00
parent 65c7e3a0cf
commit 028e85b0bf

View File

@@ -1,4 +1,4 @@
#![no_std]
// #![no_std]
use core::{error::Error, fmt::Display};
#[cfg(not(test))]
@@ -95,13 +95,13 @@ impl<const S: usize, E: PrimInt + Unsigned> TryFrom<Decimal<S, E>> 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);
}
}