rust-num / num-rational

Generic Rational numbers for Rust
Apache License 2.0
142 stars 50 forks source link

Avoid powi underflow in ratio_to_f64 #94

Closed cuviper closed 2 years ago

cuviper commented 3 years ago

Fixes #91.

cuviper commented 3 years ago

I think this may still have double-rounding, but I'm not sure how to avoid that. Perhaps we need to manually create the float from_bits, but that will need to account for a lot of corner cases. At least this PR is better than the status quo...

MattX commented 2 years ago

Yeah, other implementations of this algorithm use ldexp to avoid this issue, but while it's in libm, I don't think it's provided by Rust's stdlib. Maybe worth implementing it here?