-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
271: Implement ties-to-even for Big[U]Int::to_{f32,f64} r=cuviper a=dramforever 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 ```rust #[test] fn test() { use num::{BigInt, ToPrimitive}; let a: i128 = (1 << 120) + (1 << (120 - 53)); let b: i128 = 1 << (120 - 60); assert_ne!(a as f64, (a + 1) as f64); assert_eq!((a + b) as f64, (a + 1) as f64); assert_eq!(BigInt::from(a).to_f64().unwrap(), a as f64); // This works because the b is among the high 64 bits assert_eq!(BigInt::from(a + b).to_f64().unwrap(), (a + b) as f64); // This fails because 1 is just thrown away assert_eq!(BigInt::from(a + 1).to_f64().unwrap(), (a + 1) as f64); } ``` Co-authored-by: dramforever <[email protected]>
- Loading branch information
Showing
4 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters