]> git.sur5r.net Git - cc65/blob - testcode/lib/div-test.c
Merge remote-tracking branch 'irgendwer/AtariOS_Structure' into master
[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
7 #include <cc65.h>
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 static bool test (int dividend, int divisor)
13 {
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
22     return result.quot * divisor + result.rem != dividend;
23 }
24
25 int main (void)
26 {
27     bool t;
28
29     printf ("\nTest of division and modulus operations:\n\n");
30
31     t = test (+40, +3) ||
32         test (+40, -3) ||
33         test (-40, +3) ||
34         test (-40, -3);
35     if (t) {
36         printf ("\nThe div() function made a wrong result!\n");
37     }
38
39     if (doesclrscrafterexit ()) {
40         printf ("\nTap the Return key to quit. ");
41         getchar ();
42     }
43
44     return (int)t;
45 }