Skip to content

std::num::pow: exponent should not be a uint #16755

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

Closed
vks opened this issue Aug 25, 2014 · 1 comment
Closed

std::num::pow: exponent should not be a uint #16755

vks opened this issue Aug 25, 2014 · 1 comment

Comments

@vks
Copy link
Contributor

vks commented Aug 25, 2014

Right now pow has the following signature:

pub fn pow<T: One + Mul<T, T>>(base: T, exp: uint) -> T

It does not really make sense that the exponent is a pointer-sized uint. This makes this function unnecessarily platform-dependent.
Also, it is awkward to use with BigInt as an exponent. (This mainly an ergonomic issue, as a uint should be large enough to store any reasonable exponent.)

I think it would be better to have a signature like

pub fn pow<T: One + Mul<T, T>, U: One + Zero + Add<U, U> + Div<U,U>>(base: T, exp: U) -> T

(Note that pow currently uses some bitwise operations for efficiency, the proposed type constraints do not reflect that.)

Alternatively, to keep it simple the exponent could just be a constant-size unsigned integer (u32 should be sufficient [1]).

[1] pow(1.1, pow(2, 32)) ~= pow(10, 177780229)

@gsingh93
Copy link
Contributor

This is a valid issue that I want fixed, but it's in the wrong repo now. Could someone moves this over to https://github.com/rust-lang/num?

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2024
For toolchain binaries use the full path found in $PATH

Fixes rust-lang/rust-analyzer#16754
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants