Skip to content

Add workaround for Math.pow constant folding (only for JS builds) #2346

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

Merged

Conversation

MaxGraey
Copy link
Member

Many browsers have fast paths for Math.pow if exponents is integer-like. But it leads to imprecisions like 10 ** 208 != 1e208 or 10 ** -5 != 1e-5. For avoid this in our constant folding special case I add some clever workaround. Also add tests.

For more info see this comment: https://bugzilla.mozilla.org/show_bug.cgi?id=1775254#c13

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@MaxGraey MaxGraey requested a review from dcodeIO June 29, 2022 11:51
@dcodeIO
Copy link
Member

dcodeIO commented Jun 29, 2022

Wdyt of moving the "accurate pow" to src/util/math as a helper? Seems good to do just to separate the relevant documentation out of the compiler itself :)

@MaxGraey MaxGraey merged commit ec0b0c8 into AssemblyScript:main Jun 29, 2022
@MaxGraey MaxGraey deleted the avoid-pow-precompute-invariants branch June 29, 2022 13:12
@MaxGraey MaxGraey mentioned this pull request Jun 29, 2022
2 tasks
MaxGraey added a commit that referenced this pull request Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants