Implement ties-to-even for Big[U]Int::to_{f32,f64}#271
Implement ties-to-even for Big[U]Int::to_{f32,f64}#271bors[bot] merged 2 commits intorust-num:masterfrom
Conversation
|
I'm not quite sure how to characterize this.
|
|
In general, the goal is to match the behavior of primitive types, at least so far as that behavior does not depend on limited bit width. So yes, having an example of different Breaking changes are fuzzy when it comes to behavior -- I think this is a justified change, but yes we should mention it in release notes. There's semi-related precedent in how Rust 1.67 fixed rounding in rust-lang/rust#102935. |
This comment was marked as outdated.
This comment was marked as outdated.
2bc992c to
c75c117
Compare
BigUInt::to_{f32,f64} uses only the highest 64 bits as the mantissa,
discarding the rest, which gives an incorrect result when later
converted to float using IEEE-754's default nearest-ties-to-even
rounding.
Fixed to use correct round-to-odd for taking the mantissa, which means
setting the LSB to 1 if any of the lower (i.e. rounded away) bits are 1.
This also fixes the problem for BigInt since it really just uses BigUInt
under the hood.
c75c117 to
907fc19
Compare
|
Thanks! I just rebased this without changes to get CI running. bors r+ |
|
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
This makes the rounding consistent with primitive types, which, per IEEE-754, uses nearest-ties-to-even rounding.
See: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a6ab9b18a4982f881cd594061f096f8c