I use this crate to convert an f64 into an fps value (video framerate) consisting of u32 numerator and denominator. The documentation for Ratio::<u32>::from_f64(), for Ratio<T> and for num_traits::cast::FromPrimitive is not clear enough about what exactly it means that the input value can't "be represented by" a ratio.
I read your crate's approximate_float_unsigned() source code and, based on it, wrote the following in the doc comment of my crate's Fps::from_f64():
Returns None in the following cases (according to approximate_float_unsigned() of num-rational crate):
value < 0.0
value.is_nan()
value > u32::MAX as f64, overextending the numerator
- The conversion yields a denominator of
0.
In other cases than mine like Ratio::<u64>::from_f32(), your function's line let t_max_f = <F as NumCast>::from(t_max.clone())?; may also return None.
I'd like to be able to be forever sure about when exactly None can be returned without the necessity of "according to".
Questions/suggestions:
- Can a denominator of
0 exclusively be yielded when the input f64 is positive/negative infinity?
- Would it be possible to clarify in your documentation when exactly
None can be returned? (Possibly in the documentation for Ratio<T> with references to it in the other locations.)
I use this crate to convert an
f64into an fps value (video framerate) consisting ofu32numerator and denominator. The documentation forRatio::<u32>::from_f64(), forRatio<T>and fornum_traits::cast::FromPrimitiveis not clear enough about what exactly it means that the input value can't "be represented by" a ratio.I read your crate's
approximate_float_unsigned()source code and, based on it, wrote the following in the doc comment of my crate'sFps::from_f64():In other cases than mine like
Ratio::<u64>::from_f32(), your function's linelet t_max_f = <F as NumCast>::from(t_max.clone())?;may also returnNone.I'd like to be able to be forever sure about when exactly
Nonecan be returned without the necessity of "according to".Questions/suggestions:
0exclusively be yielded when the inputf64is positive/negative infinity?Nonecan be returned? (Possibly in the documentation forRatio<T>with references to it in the other locations.)