-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Adds pow alias for python newcomers.
#878
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
Conversation
|
You forgot the actual code. |
|
Added code. |
|
Make it work for integers too. And I prefer an inline proc. |
|
Made inline proc. Added also to complex module. How is this to work with integers? I see no |
|
|
|
So implement something like: proc pow(a, b: int): int =
var a = a
var b = b
result = 1
while true:
if (b and 1) == 1:
result *= a
b = b shr 1
if b == 0: break
a *= a |
gives me vs. casting which results in |
|
The float version is faster, but incorrect for numbers over 2**60 |
|
You could always have it use the second method for numbers above 2**60, if you're especially concerned about speed. |
|
The benchmark is flawed, you need to try different exponents and weight them by a reasonable likelihood. Hint: exponent 3 is more likely than exponent 30... |
|
** is weird, it should be ^ |
<!--- The Pull Request (=PR) message is what will get automatically used as the commit message when the PR is merged. Make sure that no line is longer than 72 characters --> ## Summary Convert `gorge` and `staticExec` in the `system` module from magics to VM callback operations. ## Details Removal of the magic requires creating a conditional compilation step based on the `nimskullReworkStaticExec` conditional symbol (see: `condsym`). Two definitions of `gorge` and `staticExec` now exist, one with the magic and one without. Without this, bootstrapping would no longer work. Also marked `gorge` as deprecated, `staticExec` is a far better name, and noted that `staticExec` will have its return type revised to return the exit code in addition to the output. The reason for the deprecation is that `gorge` is just not as clear as `staticExec`, same for `slurp`. This change enables future removal of the `mStaticExec` magic enum, and more importantly the `opcGorge` VM opcode in the near future.
## Summary * Remove `mStaticExec` and `opcGorge` as only the csources compiler needs to have them in order to bootstrap ## Details * Follow up to 'vm: convert gorge and staticExec to vmops nim-lang#878'
No description provided.