-
-
Save d7samurai/f98cb2aa30a6d73e62a65a376d24c6da to your computer and use it in GitHub Desktop.
This file contains 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
// normalized byte multiplication: | |
// range [0, 255] maps to [0.0, 1.0] | |
// examples: | |
// 0xff * 0xff = 0xff (255 * 255 = 255) | |
// 0xff * 0x7f = 0x7f (255 * 127 = 127) | |
// 0x7f * 0x7f = 0x3f (127 * 127 = 63) | |
// 0x01 * 0xff = 0x01 ( 1 * 255 = 1) | |
// 0x01 * 0x7f = 0x00 ( 1 * 127 = 0) | |
inline byte nmul(byte a, byte b) | |
{ | |
return (((uint16)a + 1) * b) >> 8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment