rust-num / num-rational

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

Implement ldexp and use it in ratio_to_f64 #104

Closed MattX closed 2 years ago

MattX commented 2 years ago

This eliminates errors where we attempt a multiplication by 2^-x, but that 2^-x underflows. (#91).

This is based on the code in #94.

The ldexp implementation strategy is mostly to extract the exponent, modify it, then reinsert it. To avoid dealing with subnormal numbers at the bit level, we shift any subnormal numbers into normal range before that operation.

Fixes #91.

cuviper commented 2 years ago

Thanks, and especially the test coverage of ldexp looks great!

bors r+

bors[bot] commented 2 years ago

Build succeeded: