summaryrefslogtreecommitdiff
path: root/test_float.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-04-01 06:56:47 -0400
committerEric S. Raymond <esr@thyrsus.com>2015-04-01 06:56:47 -0400
commita7f8c914d99c22624219ecb469b754def2e7a8d6 (patch)
tree9ca494967c4d73f43889ae0cb32977ed256fff20 /test_float.c
parenta39c59c4493399e079705fd9d45601f671c7b43b (diff)
downloadgpsd-a7f8c914d99c22624219ecb469b754def2e7a8d6.tar.gz
Add to test_float a test for C99 conformance of modular arithmetic.
Diffstat (limited to 'test_float.c')
-rw-r--r--test_float.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/test_float.c b/test_float.c
index e87c654d..6227bc8f 100644
--- a/test_float.c
+++ b/test_float.c
@@ -26,6 +26,9 @@
* Hard To Do(tm) on embedded systems, judging by the number of broken
* ARM toolchains I've seen... :(
*
+ * Added in 2015 by ESR: Test for C99 behavior on negative operand(s)
+ * of %, that is the result should have the sign of the left operand.
+ *
* compile with: gcc -O -o test_float test_float.c
* (use whatever -O level you like)
*/
@@ -33,9 +36,10 @@
int main(void);
int test_single(void);
int test_double(void);
+int test_modulo(void);
int main(void) {
- int i, j;
+ int i, j, k;
if ((i = test_single()))
printf("WARNING: Single-precision "
@@ -45,9 +49,13 @@ int main(void) {
printf("WARNING: Double-precision "
"floating point math might be broken\n");
+ if ((k = test_modulo()))
+ printf("WARNING: Modular arithmetic is broken\n");
+
i += j;
+ i += k;
if (i == 0)
- printf("floating point math appears to work\n");
+ printf("floating point and modular math appears to work\n");
return i;
}
@@ -257,3 +265,28 @@ int test_double(void) {
}
return 0;
}
+
+int test_modulo(void) {
+ static int e = 0;
+
+ if (-5 % 2 != -1) {
+ printf("m1 ");
+ e++;
+ }
+
+ if (-5 % -2 != -1) {
+ printf("m2 ");
+ e++;
+ }
+
+ if (5 % -2 != 1) {
+ printf("m3 ");
+ e++;
+ }
+
+ if (e) {
+ printf("\n");
+ return 1;
+ }
+ return 0;
+}