rust-num / num-rational

Generic Rational numbers for Rust
Apache License 2.0
144 stars 51 forks source link

From instance for f64 and f32 #40

Closed droundy closed 5 years ago

droundy commented 5 years ago

It would be lovely to be able to convert floating points to rational numbers.

cuviper commented 5 years ago

Ratio<BigInt>::from_float should be able to handle any finite value precisely, but returns None for infinities and NaN. The more general Ratio<T>::approximate_float makes a best effort for other integer types, but can also fail if the numerator or denominator would be out of range.

Neither of these are From since they are fallible.

droundy commented 5 years ago

I missed this somehow. Thanks!