]> git.sur5r.net Git - cc65/blob - testcode/lib/div-test.c
clock-test.c: remove "static" optimization
[cc65] / testcode / lib / div-test.c
1 /* div-test.c
2 **
3 ** This program tests the division and modulo operators
4 ** and the div() library function.
5 **
6 ** 2002-10-24, Greg King
7 */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stdbool.h>
12
13 static bool test(int dividend, int divisor) {
14         div_t result;
15
16         result = div(dividend, divisor);
17         printf("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n",
18                 dividend, divisor, dividend / divisor,
19                 dividend, divisor, dividend % divisor,
20                 result.quot, result.rem);
21         return result.quot * divisor + result.rem != dividend;
22         }
23
24 int main(void) {
25         bool t;
26
27         printf("\nTest of division and modulus operations:\n\n");
28         t =     test(+40, +3) ||
29                 test(+40, -3) ||
30                 test(-40, +3) ||
31                 test(-40, -3);
32         if (t)
33                 printf("\nThe div() function made a wrong result!\n");
34
35         printf("\nTap a key, to exit. ");
36         getchar();
37         return (int)t;
38         }