-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Specify negative-returning behavior of abs
method
#16707
Comments
For reference, this is the behavior of Java, C, and C++. But C# yields an error when this is done. Java in particular documents Math.abs on ints to be:
While C# simply states that the input is:
A third alternative exists in making the output of min be the unsigned version of the input, which should be possible with associated types. You can actually do this today with |
Maybe we should document this so there is no confusion? |
Similar issues for rationals: extern crate num;
use std::i64::MIN;
use num::rational::Ratio;
let a = Ratio::new(MIN, 1);
a.abs() == a; // true Hmm, I originally thought that we should settle some agreement about negative-returning behaviors and add some notes like "Note: implementation may return negative value if it is impossible to represent correctly". |
Export `SemanticsImpl` from `ra_ap_hir` crate, since it's already exposed via `Semantics.deref()` The `SemanticsImpl` type is already de-facto exposed via `<Semantics as Deref>::Target`. By not being part of the public crate interface it however doesn't get included in the documentation, resulting in a massive blind spot when it comes to `ra_ap_hir`'s type resolution APIs.
Currently
::std::i64::MIN.abs()
returns::std::i64::MIN
.I don't think this is absolutely "wrong", but then at least it should be specified that "abs() method can return negative values".
Currently
std::num::abs()
says it can return NaN for floats, but no mention for general situation.The text was updated successfully, but these errors were encountered: