]> git.sur5r.net Git - cc65/commitdiff
Added a test program for division and modulo operation.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 11 Jan 2011 17:19:16 +0000 (17:19 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Tue, 11 Jan 2011 17:19:16 +0000 (17:19 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4906 b7a2c559-68d2-44c3-8de9-860c34a00d81

testcode/lib/moddiv-test.c [new file with mode: 0644]

diff --git a/testcode/lib/moddiv-test.c b/testcode/lib/moddiv-test.c
new file mode 100644 (file)
index 0000000..b8ea19d
--- /dev/null
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+int main (void)
+{
+    int a, b;
+    int div, mod;
+
+    printf ("Please note that this program does an\n"
+            "exhaustive test for the division and\n"
+            "modulo operation and therefore runs for\n"
+            "almost ever. On my box, it's nearly two\n"
+            "days in warp mode of VICE.\n\n");
+
+    a = 0;
+    do {
+        b = 1;
+        do {
+            div = a / b;
+            mod = a % b;
+            if (div * b + mod != a) {
+                printf ("Found problems:\n"
+                        "  Result of %u / %u is %u\n"
+                        "  Result of %u %% %u is %u\n",
+                        a, b, div, a, b, mod);
+                return EXIT_FAILURE;
+            }
+            ++b;
+        } while (b != 0);
+        if ((a & 0xFF) == 0) {
+            printf ("%5u ", a);
+        }
+        ++a;
+    } while (a != 0);
+    return EXIT_SUCCESS;
+}