-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
libcore: add num::Int::pow() and deprecate num::pow(). #19031
Conversation
/// assert_eq!(num::pow(2i, 4), 16); | ||
/// ``` | ||
#[inline] | ||
pub fn pow<T: Int>(mut base: T, mut exp: uint) -> T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be #[deprecated]?
I think that the design of The cc @aturon |
I agree with @alexcrichton; please see the numerics reform RFC for details. I had been thinking we could/should move |
cc @bjz |
Signed-off-by: NODA, Kai <[email protected]>
4ed161a
to
3fcf284
Compare
@gankro Yeah, I shouldn't have been so brutal! I deprecated the free function @alexcrichton @aturon Now this PR is only about the |
The |
/// assert_eq!(2i.pow(4), 16); | ||
/// ``` | ||
#[inline] | ||
fn pow(self, mut exp: uint) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did the implementation change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified the code by removing the special case for exp==1
because we don't have the move semantics with primitive integers. exp /= 2
is more readable than exp = exp >> 1
and equivalent to it:
- http://is.gd/cYcfFU (hit the [ir] button)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing LLVM would optimise to a bit shift anyway.
What do you mean by 'don't have the move semantics with primitive integers'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc. @huonw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjz The original code could move the base
parameter to the caller as its return value when exp
is 1
. It could perhaps achieve better performance only with bigint objects whose initialization cost was not negligible.
Updated the issue title and description. |
[breaking-change] Deprecates `core::num::pow` in favor of `Int::pow`.
[breaking-change]
Deprecates
core::num::pow
in favor ofInt::pow
.