You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose to add a trait to explicitly allow rational approximation for various types. This is motivated by my crate for irrational numbers where I would like to have a unified interface for approximation (see #35 (comment)).
Here's a draft:
pubenumApproximation<T>{Approximated(T),Exact(T)}pubtraitRationalApproximation<T:Integer>{// Here `limit` determines the (absolute?) maximum of the numerator and denumerator fnapprox_rational(&self,limit:&T) -> Approximation<Ratio<T>>;}
There're several benefits to define this interface:
If we implement RationalApproximation for Ratio<T> itself, then we can have an explicit method to limit the precision of the fraction. (related to Feature request: Limiting precision #99)
Other number types can use this interface to provide approximation ability (such as my irrational number types)
The existing from_float and approximate_float functions seem messy to me. I would suggest to keep the from_float method, while implements RationalApproximation for f32 and f64.
Thanks!
The text was updated successfully, but these errors were encountered:
Besides, from_float could be implemented as a TryFrom trait. And as we have From<T: Integer>, from_integer seems unnecessary for me. It makes user confusing.
Another option might be deprecate from_float as well, this functionality will be only available through FromPrimitive::{from_f32, from_f64}.
I propose to add a trait to explicitly allow rational approximation for various types. This is motivated by my crate for irrational numbers where I would like to have a unified interface for approximation (see #35 (comment)).
Here's a draft:
There're several benefits to define this interface:
RationalApproximation
forRatio<T>
itself, then we can have an explicit method to limit the precision of the fraction. (related to Feature request: Limiting precision #99)from_float
andapproximate_float
functions seem messy to me. I would suggest to keep thefrom_float
method, while implementsRationalApproximation
forf32
andf64
.Thanks!
The text was updated successfully, but these errors were encountered: