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

fix: division by zero on 32-bit platform (#107, #118) #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jixunmoe
Copy link

@jixunmoe jixunmoe commented Nov 13, 2023

A rewrite of the animal-name to number converter functions. This is an attempt to get the program to work under 32-bit system (e.g. an armv7 device).

Also included some simple test, made before the change.

The issue was caused by ANIMAL_NAMES.len().pow(power), where power=6, overflows 32-bit integer to 0x10_0000_0000. Is this a bug in Rust? No idea. The old implementation can have issues when the number exceeds this limit.

This might also be faster (no benchs) - since we are having exactly 64 items, this can be optimized to bit-wise operations nicely by rust.

This PR should fix the following issues:

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.

None yet

1 participant