mirror of
https://github.com/cc65/cc65.git
synced 2025-01-03 01:31:55 +00:00
Division test program by Greg King
git-svn-id: svn://svn.cc65.org/cc65/trunk@1471 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
55baa52735
commit
047ecd1955
40
testcode/lib/div-test.c
Normal file
40
testcode/lib/div-test.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* 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;
|
||||||
|
|
||||||
|
(long)result = (long)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");
|
||||||
|
#ifdef __ATARI__
|
||||||
|
/* Atari DOS 2 clears the screen after program-termination, so wait. */
|
||||||
|
printf("\nTap a key, to exit. ");
|
||||||
|
getchar();
|
||||||
|
#endif
|
||||||
|
return (int)t;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user