You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm open to it, if we can present it in a generic trait befitting the rest of the crate. That doesn't mean that you have to have a generic implementation, just that it's designed such that things like BigUint can implement it too. Take the Roots trait, for example.
The unsigned primitive integers already have is_power_of_two, and a related next_power_of_two. It would be good to also abstract this in a trait, while we're doing it for 10. Something like:
Or maybe just combine those into a single trait Powers. And feel free to suggest a better name.
Could we reasonably implement checks for arbitrary powers of n? It wouldn't have to be as fast, but I'm wondering if that's feasible and useful to have too.
A separate trait is consistent with the way I was thinking about it.
Curious, why don't signed primitive integers implement is_power_of_two? (obviously, all negative numbers would return false).
How would we abstract over arbitrary powers on n? Extra parameter to the method? I think 2 and 10 are sufficiently interesting to have their own trait.
Activity
cuviper commentedon Nov 14, 2018
I'm open to it, if we can present it in a generic trait befitting the rest of the crate. That doesn't mean that you have to have a generic implementation, just that it's designed such that things like
BigUintcan implement it too. Take theRootstrait, for example.The unsigned primitive integers already have
is_power_of_two, and a relatednext_power_of_two. It would be good to also abstract this in a trait, while we're doing it for 10. Something like:Or maybe just combine those into a single
trait Powers. And feel free to suggest a better name.Could we reasonably implement checks for arbitrary powers of
n? It wouldn't have to be as fast, but I'm wondering if that's feasible and useful to have too.cuviper commentedon Nov 14, 2018
Floored
log2andlog10might also fit into the scope of this design.mohrezaei commentedon Nov 14, 2018
A separate trait is consistent with the way I was thinking about it.
Curious, why don't signed primitive integers implement
is_power_of_two? (obviously, all negative numbers would return false).How would we abstract over arbitrary powers on
n? Extra parameter to the method? I think 2 and 10 are sufficiently interesting to have their own trait.cuviper commentedon Nov 14, 2018
I'm not sure, but probably just because negative inputs are useless if they're all
false.Similarly, what would
next_power_of_twodo with a negative -- jump all the way to1?Yeah,
fn is_power_of_n(&self, n: u32) -> bool, or mayben: usizeorn: &Self. I'm not sure if this is really useful anywhere, just musing.mohrezaei commentedon Nov 14, 2018
Alright, that gives me enough to move this over to a PR. Expect something in the next few days. 😄