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

Computation of checkbits could be cleaned up #75

Closed
davemc0 opened this issue Mar 31, 2022 · 1 comment
Closed

Computation of checkbits could be cleaned up #75

davemc0 opened this issue Mar 31, 2022 · 1 comment

Comments

@davemc0
Copy link

davemc0 commented Mar 31, 2022

The lines that compute checkbits (the curve order or bits per dimension) currently use floating-point math, including floor(), which is not a trivial function, depending perhaps on the floating point handling, i.e. /fp:strict.

Here's an example:

unsigned int checkbits = static_cast<unsigned int>(floor((sizeof(morton) * 8.0f / 3.0f)));

This code can be replaced with the following:
unsigned int checkbits = (sizeof(morton) * 8) / 3;

This uses integer division, includes no function call, and gives the same results in all cases.

The key to this working is the order of operations - doing the multiply first gives an intermediate result of 64 or 32. Dividing this by three yields 21 or 10, as desired.

@Forceflow
Copy link
Owner

Fixed in e01292d

The for-loop path is purely there for educational purposes (since it is the most transparent but slowest method to compute morton codes), but this is a nice improvement anyway.

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