Created
January 29, 2013 14:41
-
-
Save eraserhd/4664724 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Yields the approximate result of a division by 1000. | |
// NOTE: Can only be used for numbers less than 140,737,488,290 | |
unsigned long quickDiv1000(unsigned long num) | |
{ | |
unsigned long result; | |
result = num * 65 + (num >> 2) + (num >> 5) + (num >> 8)+ (num >> 11) + 32768; | |
return (result >> 16); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
working translation:
fuction: returns approximate result of division by 1000 (fucked in some edge cases)
parameters: incoming (integer)
intermediate = incoming * (2^6 + 1) + (incoming/2^1) + (incoming/2^5) + (incoming/2^8)+ (incoming/2^11) + 2^15
return (intermediate/2^16)