Last active
July 28, 2017 18:36
-
-
Save warpling/88b24f19697d495c3780640c77fc8953 to your computer and use it in GitHub Desktop.
MAPRANGE
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
// Maps one range onto another | |
// Example: [-50, 100] to [0, 1.0] | |
// Example: [0.2, 1.0] to [1.0, 0.0] | |
#define MAPRANGE(x, inputLow, inputHigh, outputLow, outputHigh) ({\ | |
__typeof(x) __x = (x); \ | |
__typeof(inputLow) __inputLow = (inputLow); \ | |
__typeof(inputHigh) __inputHigh = (inputHigh); \ | |
__typeof(outputLow) __outputLow = (outputLow); \ | |
__typeof(outputHigh) __outputHigh = (outputHigh); \ | |
(((__x - __inputLow) / (__inputHigh - __inputLow)) * (__outputHigh - __outputLow)) + __outputLow; \ | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment