2024-02-24 22:35:25 +05:30
|
|
|
/*
|
|
|
|
* opt_int_div.c
|
|
|
|
*
|
2024-02-25 03:39:36 +05:30
|
|
|
* "Optimized integer division"
|
|
|
|
*
|
2024-02-24 22:35:25 +05:30
|
|
|
* Author: Intel A80486DX2-66
|
|
|
|
* License: Creative Commons Zero 1.0 Universal
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "opt_int_div.h"
|
|
|
|
|
2024-03-24 18:32:31 +05:30
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
2024-02-24 22:35:25 +05:30
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
printf("Loop: a > 0, b > 0\n");
|
|
|
|
for (uint8_t a = 3; a <= 24; a++)
|
|
|
|
for (uint8_t b = 1; b <= 8; b++) {
|
|
|
|
if (b >= a)
|
|
|
|
break;
|
|
|
|
printf("%" PRIu8 " / %" PRIu8 " = %" PRIu8 "\n", a, b,
|
|
|
|
OPT_INT_DIV(a, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Loop: a < 0, b > 0\n");
|
|
|
|
for (int8_t a = -3; a >= -24; a--)
|
|
|
|
for (int8_t b = 1; b <= 8; b++) {
|
|
|
|
if (b >= abs(a))
|
|
|
|
break;
|
|
|
|
printf("%" PRId8 " / %" PRId8 " = %" PRId8 "\n", a, b,
|
|
|
|
OPT_INT_DIV(a, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Loop: a < 0, b < 0\n");
|
|
|
|
for (int8_t a = -3; a >= -24; a--)
|
|
|
|
for (int8_t b = -1; b >= -8; b--) {
|
|
|
|
if (b <= a)
|
|
|
|
break;
|
|
|
|
printf("%" PRId8 " / %" PRId8 " = %" PRId8 "\n", a, b,
|
|
|
|
OPT_INT_DIV(a, b));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|