diff options
| author | Michael Matz <matz@suse.de> | 2014-01-12 04:44:27 +0100 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2014-01-12 04:44:27 +0100 |
| commit | 05c9b76131e9d0a2e1b011eeb70ad7897efc9084 (patch) | |
| tree | 6bb541490c316505c2a9ffccc39507057b4a6b1c /tests | |
| parent | 9c6ddbfe903445763405d2c8bdec916c8a20f105 (diff) | |
| download | tinycc-05c9b76131e9d0a2e1b011eeb70ad7897efc9084.tar.gz tinycc-05c9b76131e9d0a2e1b011eeb70ad7897efc9084.tar.bz2 | |
Fix floating point unary minus and plus
negate(x) is subtract(-0,x), not subtract(+0,x), which makes
a difference with signed zeros. Also +x was expressed as x+0,
in order for the integer promotions to happen, but also mangles signed
zeros, so just don't do that with floating types.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/tcctest.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c index eb284f0..d96c5a1 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1699,6 +1699,29 @@ void prefix ## call(void)\ printf("strto%s: %f\n", #prefix, (double)strto ## prefix("1.2", NULL));\ }\ \ +void prefix ## signed_zeros(void) \ +{\ + type x = 0.0, y = -0.0, n, p;\ + if (x == y)\ + printf ("Test 1.0 / x != 1.0 / y returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / y);\ + else\ + printf ("x != y; this is wrong!\n");\ +\ + n = -x;\ + if (x == n)\ + printf ("Test 1.0 / x != 1.0 / -x returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / n);\ + else\ + printf ("x != -x; this is wrong!\n");\ +\ + p = +y;\ + if (x == p)\ + printf ("Test 1.0 / x != 1.0 / +y returns %d (should be 1).\n",\ + 1.0 / x != 1.0 / p);\ + else\ + printf ("x != +y; this is wrong!\n");\ +}\ void prefix ## test(void)\ {\ printf("testing '%s'\n", #typename);\ @@ -1708,6 +1731,7 @@ void prefix ## test(void)\ prefix ## fcast(234.6);\ prefix ## fcast(-2334.6);\ prefix ## call();\ + prefix ## signed_zeros();\ } FTEST(f, float, float, "%f") |
