fix: avoid no_std panic in ceil helpers on non-finite input

Byte::from_f64/from_f32 let +inf past the size >= 0.0 guard and then called
the no_std ceil helpers, which used Decimal::from_f64(v).unwrap(). Decimal
conversion returns None for non-finite values, so this panicked in no_std
builds while std returned None. Fall back to the input value for non-finite
input so no_std matches std and the documented None contract is upheld.
This commit is contained in:
dualfroz committed 2026-09-04 09:45:03 +02:00
1 parent 85f79fa753
commit bf130b54f8
3 files changed
+109 -2

No files matched your search

+10
View File
@@ -170,3 +170,13 @@ fn tests() {
assert_eq!(byte, serde_json::from_str::<Byte>(case.0).unwrap(), "{i}");
}
}
#[test]
fn from_non_finite_returns_none() {
// Non-finite inputs are "too large" and must return None instead of
// panicking, consistently across the `std` and `no_std` builds.
assert_eq!(Byte::from_f64(f64::INFINITY), None);
assert_eq!(Byte::from_f64(f64::NAN), None);
assert_eq!(Byte::from_f32(f32::INFINITY), None);
assert_eq!(Byte::from_f32(f32::NAN), None);
}