Skip to content

Instantly share code, notes, and snippets.

@madex
Created October 20, 2014 10:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madex/5daf4a673103449240da to your computer and use it in GitHub Desktop.
Save madex/5daf4a673103449240da to your computer and use it in GitHub Desktop.
division by 10 as multply an shift.
// (uint64_t val) 26 till 11184819 correct, (uint32_t val) 19 bis 81920 correct
#define BITS 19
#define MUL (((1L << BITS)/10) + 1)
unsigned long div10(unsigned long val) {
return ((unsigned long) val * MUL) >> BITS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment