Skip to content

Instantly share code, notes, and snippets.

@ahills60
Created October 8, 2018 16:57
Show Gist options
  • Save ahills60/83c53c9a9c6461baf978376154c2cae2 to your computer and use it in GitHub Desktop.
Save ahills60/83c53c9a9c6461baf978376154c2cae2 to your computer and use it in GitHub Desktop.
Compute the ceiling of an integer division without floating point
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#define ceilu32(x, y) ((((((uint32_t) x) << 16) / (uint32_t) y) + 0xffff) >> 16)
int main(void)
{
uint16_t var1, var2, result;
for (var1 = 1; var1 <= 50000; var1++)
{
for (var2 = 1; var2 <= 50000; var2++)
{
result = ceilu32((var1, var2);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment