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

Allow encoding/decoding with higher precision #82

Merged
merged 1 commit into from
Apr 6, 2023

Conversation

MoonE
Copy link
Contributor

@MoonE MoonE commented Apr 5, 2023

Bit operations only work on 32 bit ints. The work around is to don't use bit operations where large numbers may occur.

Fixes #80

Bit operations only work on 32 bit ints. The work around is to don't
use bit operations where large numbers may occur.
}
output += String.fromCharCode(coordinate + 63);
output += String.fromCharCode((coordinate | 0) + 63);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
output += String.fromCharCode((coordinate | 0) + 63);
output += String.fromCharCode((coordinate || 0) + 63);

Copy link
Contributor Author

@MoonE MoonE Apr 6, 2023

Choose a reason for hiding this comment

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

This is intentionally a bitwise OR. In the String.fromCharCode() call in the loop above, the bitwise operation causes decimals to be discarded. I added the | 0 to remove decimals here too. I wasn't sure if a number with decimals would cause problems. In my test it worked also without rounding, but you never know how different browsers treat it ...

@tristen tristen merged commit 6984850 into mapbox:master Apr 6, 2023
@MoonE MoonE deleted the high-precision branch April 6, 2023 20:48
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.

Precision parsing is wrong in some cases
2 participants