-
Notifications
You must be signed in to change notification settings - Fork 63
Open
Description
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:
pub enum Approximation<T> {
Approximated(T),
Exact(T)
}
pub trait RationalApproximation<T: Integer> {
// Here `limit` determines the (absolute?) maximum of the numerator and denumerator
fn approx_rational(&self, limit: &T) -> Approximation<Ratio<T>>;
}There're several benefits to define this interface:
- If we implement
RationalApproximationforRatio<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_floatandapproximate_floatfunctions seem messy to me. I would suggest to keep thefrom_floatmethod, while implementsRationalApproximationforf32andf64.
Thanks!
schneiderfelipe
Metadata
Metadata
Assignees
Labels
No labels