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

Implement a faster fraction to monzo + residual converter #24

Merged
merged 1 commit into from
Apr 20, 2024

Conversation

frostburn
Copy link
Member

Use a precalculated table for 7-limit conversion.

Copy link

@arseniiv arseniiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can’t seem to fix my gaze on smallest detail but I guess it’s still some more evidence that the code should be okay.

// Factors of two using bit magic
const twos = (n ^ (n - 1n)) & n;
n /= twos;
result[0] += Math.log2(Number(twos));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is fast but right near bit magic it feels weird. Though of course bit magic is here just to count zeros at least semi-efficiently and not to be blazing fast, so there’s no contradiction anywhere in the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me uneasy as well. I'll add an apology in a comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually breaks with 2n ** 1024n. 😅

Use a precalculated table for 7-limit conversion.
@frostburn
Copy link
Member Author

Doesn't break tests over at sonic-weave. Effect on test suite execution speed is basically lost in the noise so some profiling is in order before doing more premature optimization like this.

@frostburn frostburn merged commit 1913ea5 into main Apr 20, 2024
1 check passed
@frostburn frostburn deleted the gotta-go-fast branch April 20, 2024 07:56
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