1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-03 10:07:02 +00:00
cc65/testcode/lib/div-test.c
Oliver Schmidt 98c47d1877 Introduced target 'atarixl'.
The target 'atarixl' is to be used for Atari XL (and better) machines.
It will disable the OS ROM and enable the Shadow RAM available on
those machine.

Note: This commit is only the inital step towards for this goal that just
replicates the target 'atari' as a starting point!
2013-05-28 21:56:37 +02:00

39 lines
1013 B
C

/* div-test.c
**
** This program tests the division and modulo operators
** and the div() library function.
**
** 2002-10-24, Greg King
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
static bool test(int dividend, int divisor) {
div_t result;
result = div(dividend, divisor);
printf("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n",
dividend, divisor, dividend / divisor,
dividend, divisor, dividend % divisor,
result.quot, result.rem);
return result.quot * divisor + result.rem != dividend;
}
int main(void) {
bool t;
printf("\nTest of division and modulus operations:\n\n");
t = test(+40, +3) ||
test(+40, -3) ||
test(-40, +3) ||
test(-40, -3);
if (t)
printf("\nThe div() function made a wrong result!\n");
printf("\nTap a key, to exit. ");
getchar();
return (int)t;
}