Skip to content
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

Use integer power "**" operator for integer types #210

Closed
MaxGraey opened this issue Aug 4, 2018 · 10 comments
Closed

Use integer power "**" operator for integer types #210

MaxGraey opened this issue Aug 4, 2018 · 10 comments

Comments

@MaxGraey
Copy link
Member

MaxGraey commented Aug 4, 2018

Once day Vitalik Buterin published this twit about one counter example in Javascript using Fermat's Last Theorem:

57055**3 + 339590**3 == 340126**3
> true

That's happened because JS/TS using float point numbers all the time except logical ops.
In AS we have more rich set of types but power (**) operator still use Math.pow under the hood. This unfortunately cause to the same problem as in JS/TS and increase size of code btw.

@MaxGraey MaxGraey changed the title Use integer power for "**" operator Use integer power "**" operator for integer types Aug 4, 2018
@dcodeIO
Copy link
Member

dcodeIO commented Aug 4, 2018

There is no specific reason to use floating point Math.pow for everything, except, maybe, that this is what JS does. I agree though that integer-specific exponentiation would be a nice addition.

@MaxGraey
Copy link
Member Author

MaxGraey commented Aug 5, 2018

In python for integers operands, the result has the same type as the operands (after coercion) unless the second argument is negative in this case pow '**' return float result. Will be great have the same behaviour

@dcodeIO
Copy link
Member

dcodeIO commented Aug 5, 2018

Do you know a good ipow (or how it's named) implementation that we could implement? :)

@MaxGraey
Copy link
Member Author

MaxGraey commented Aug 5, 2018

Hmm, I don't know about performance of my implementation but I tried speedup ipow calculation as much as possible. We could get this as proof of concept but for smaller types implementation could be more simplicity without some extra checks. Also compiler should provide precomputing cases when all arguments is constant like 57055**3. I could start implement this for std, WDYT?

@dcodeIO
Copy link
Member

dcodeIO commented Feb 7, 2019

@MaxGraey Has this been solved by your PR?

@MaxGraey
Copy link
Member Author

MaxGraey commented Feb 7, 2019

Not yet. It require some stuff from compiler side as well.

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closing this issue as part of 2020 vacuum as it is now tracked by the respective PR, which is nearing completion.

@dcodeIO dcodeIO closed this as completed May 27, 2020
@MaxGraey MaxGraey reopened this May 27, 2020
@MaxGraey
Copy link
Member Author

MaxGraey commented May 27, 2020

It still WIP here: #1146 and will finished soon

@dcodeIO
Copy link
Member

dcodeIO commented May 27, 2020

Closed this because I thought that having both an issue and a PR, that is nearly finished, isn't necessary. But if you prefer to keep it open, I'm ok with that :)

@dcodeIO dcodeIO added vacuumed and removed vacuumed labels May 27, 2020
@MaxGraey
Copy link
Member Author

Implemented in #1146

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants