Created
January 6, 2014 19:39
-
-
Save Linux-cpp-lisp/8288518 to your computer and use it in GitHub Desktop.
A little function to take a value in the range 0-x and convert them to values in a different, smaller range.
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
unsigned int num_range_shrink(unsigned int orig, unsigned int old_limit, unsigned int new_upper) { | |
float interval = old_limit / new_upper; | |
for(int i = 1; i <= new_upper; i++) { | |
if(orig < i*interval) { | |
return i-1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment