We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extern crate num; use num::rational::BigRational; fn main() { let x = from_str::<BigRational>("2/5").unwrap(); println!("{}, {}", x, x.round()); }
Prints "2/5, 1".
The method is written here: http://static.rust-lang.org/doc/master/src/num/home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libnum/rational.rs.html#138-140
pub fn round(&self) -> Ratio<T> { if *self < Zero::zero() { Ratio::from_integer((self.numer - self.denom + One::one()) / self.denom) } else { Ratio::from_integer((self.numer + self.denom - One::one()) / self.denom) } }
The text was updated successfully, but these errors were encountered:
Fix issue rust-lang#15826.
687db5d
The implemented fix rounds half-way cases away from zero as described in the original comments. This rounding algorithm is sometimes called arithmetic rounding. It is described further here: http://en.wikipedia.org/wiki/Rounding#Round_half_away_from_zero I also added several new tests to prevent regressions.
The rounding error was fixed by #16778. This issue can be closed.
Sorry, something went wrong.
Thanks @jbcrail!
No branches or pull requests
Prints "2/5, 1".
The method is written here:
http://static.rust-lang.org/doc/master/src/num/home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libnum/rational.rs.html#138-140
The text was updated successfully, but these errors were encountered: