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 Math.log2 instead of Math.log / Math.LN2 #504

Merged
merged 1 commit into from
Oct 28, 2024
Merged

Conversation

kirillgroshkov
Copy link
Contributor

I have noticed that this line in index.browser.js:

let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1

uses Math.log() / Math.LN2 to get the log2,

while it can be made shorter by using widely available Math.log2 method:

let mask = (2 << Math.log2(alphabet.length - 1)) - 1

How did I notice it?

Because there's an eslint rule that recommends that: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-modern-math-apis.md#prefer-mathlog2x-over

Math.log2 seems to be widely available in the Browsers and I see no reason why it shouldn't be used.

@ai ai merged commit d6f0d53 into ai:main Oct 28, 2024
5 checks passed
@ai
Copy link
Owner

ai commented Oct 28, 2024

Thanks. Released in 5.0.8.

@kirillgroshkov kirillgroshkov deleted the patch-1 branch October 28, 2024 11:37
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

Successfully merging this pull request may close these issues.

2 participants