Skip to content

Instantly share code, notes, and snippets.

@d7samurai
Created July 30, 2018 16:23
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d7samurai/f98cb2aa30a6d73e62a65a376d24c6da to your computer and use it in GitHub Desktop.
Save d7samurai/f98cb2aa30a6d73e62a65a376d24c6da to your computer and use it in GitHub Desktop.
// 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