-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Float::abs_sub isn't working properly #22105
New issue
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
Comments
These call the C function
so this behaviour seems rather confusing, and may be a bug in libm?? |
Oh, no, it's just an operator precedence thing: Adding the parens makes it behave as expected: #![feature(std_misc)]
fn main() {
use std::num::Float;
// Rules:
// - If `self < other`: `0`
// - Otherwise `self - other`
assert_eq!((-3.0f64).abs_sub(2.0), 0.0);
assert_eq!((-3.0f64).abs_sub(-2.0), 0.0);
assert_eq!((-1.0f64).abs_sub(-2.0), 1.0);
} Closing as not-a-bug, but thanks for checking things so carefully! |
Hmm...that's a downside to using method syntax here. I can see that tripping people up often but don't see a way around it except recommending save to variables before calling the methods. @huonw thanks! |
I'm not sure what
Float::abs_sub()
is supposed to do but it's not working correctly.The text was updated successfully, but these errors were encountered: