-
Couldn't load subscription status.
- Fork 78
Description
NotNan<f64> should implement From<i8>, From<i16>, From<i32>, From<u8>, From<u16> and From<u32>, NotNan<f32> should implement From<i8>, From<i16>, From<u8> and From<u16>.
Recently I was in the situation of having to convert from an i32 to a NotNan<f64> due to a character size to percent of screen conversion (seems pointless, but has it's reasons). Since that conversion happened quite often in my program, I wanted to make the conversion as simple as possible, and ended up with this function:
fn i32_to_notnan_f64(source: i32) -> NotNan<f64> {
// SAFETY: source is an i32, and an i32 cannot hold a value that f64::from would convert to NaN
// as it doesn't have any "special" values
unsafe { NotNan::new_unchecked(f64::from(source)) }
}And actually, I don't see any complications with this being the implementation of impl From<i32> for NotNan<f64>. But it's very possible that I missed something, so I'm here opening this issue first before I break down the door with an PR.