-
Notifications
You must be signed in to change notification settings - Fork 59
Description
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 toapproximate_float_unsigned()
ofnum-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 inputf64
is positive/negative infinity? - Would it be possible to clarify in your documentation when exactly
None
can be returned? (Possibly in the documentation forRatio<T>
with references to it in the other locations.)