From 8c5fba684c4868dd312d6367f7505fd40c76c023 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 9 Jan 2022 16:51:40 -0600 Subject: [PATCH] Add tests for fp comparison macros and type-generic math macros. --- Tests/Conformance/DOIT3 | 3 +- Tests/Conformance/c99fpcmp.c | 92 +++++++++++++++++++++++++++++++++++ Tests/Conformance/c99tgmath.c | 85 ++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 Tests/Conformance/c99fpcmp.c create mode 100644 Tests/Conformance/c99tgmath.c diff --git a/Tests/Conformance/DOIT3 b/Tests/Conformance/DOIT3 index cd0add8..1a5fb1b 100644 --- a/Tests/Conformance/DOIT3 +++ b/Tests/Conformance/DOIT3 @@ -19,6 +19,8 @@ {1} c99locale.c {1} c99stdarg.c {1} c99math.c +{1} c99fpcmp.c +{1} c99tgmath.c {1} c11generic.c {1} c11align.c {1} c11noret.c @@ -26,4 +28,3 @@ {1} c11sassert.c {1} c11unicode.c {1} c11uchar.c - diff --git a/Tests/Conformance/c99fpcmp.c b/Tests/Conformance/c99fpcmp.c new file mode 100644 index 0000000..127866c --- /dev/null +++ b/Tests/Conformance/c99fpcmp.c @@ -0,0 +1,92 @@ +/* + * Test floating-point comparison macros (C99). + */ + +#include +#include +#include + +float nan_ = NAN; + +#pragma STDC FENV_ACCESS ON + +int main(void) { + if (!isgreater(1.0, -3.0)) + goto Fail; + if (isgreater(-5e20L, -5e20L)) + goto Fail; + if (isgreater(5.0F, 7.0F)) + goto Fail; + if (isgreater(nan_, 1.0L)) + goto Fail; + if (isgreater(-INFINITY, -3.0)) + goto Fail; + + if (!isgreaterequal(1.0, -3.0)) + goto Fail; + if (!isgreaterequal(-5e20L, -5e20L)) + goto Fail; + if (isgreaterequal(5.0F, 7.0F)) + goto Fail; + if (isgreaterequal(nan_, 1.0L)) + goto Fail; + if (isgreaterequal(-INFINITY, -3.0)) + goto Fail; + + if (isless(1.0, -3.0)) + goto Fail; + if (isless(-5e20L, -5e20L)) + goto Fail; + if (!isless(5.0F, 7.0F)) + goto Fail; + if (isless(nan_, 1.0L)) + goto Fail; + if (!isless(-INFINITY, -3.0)) + goto Fail; + + if (islessequal(1.0, -3.0)) + goto Fail; + if (!islessequal(-5e20L, -5e20L)) + goto Fail; + if (!islessequal(5.0F, 7.0F)) + goto Fail; + if (islessequal(nan_, 1.0L)) + goto Fail; + if (!islessequal(-INFINITY, -3.0)) + goto Fail; + + if (!islessgreater(1.0, -3.0)) + goto Fail; + if (islessgreater(-5e20L, -5e20L)) + goto Fail; + if (!islessgreater(5.0F, 7.0F)) + goto Fail; + if (islessgreater(nan_, 1.0L)) + goto Fail; + if (!islessgreater(-INFINITY, -3.0)) + goto Fail; + + if (isunordered(1.0, -3.0)) + goto Fail; + if (isunordered(-5e20L, -5e20L)) + goto Fail; + if (isunordered(5.0F, 7.0F)) + goto Fail; + if (!isunordered(nan_, 1.0L)) + goto Fail; + if (isunordered(-INFINITY, -3.0)) + goto Fail; + if (!isunordered(INFINITY, nan_)) + goto Fail; + if (!isunordered(nan_, nan_)) + goto Fail; + + if (fetestexcept(FE_INVALID)) + goto Fail; + + printf ("Passed Conformance Test c99fpcmp\n"); + return 0; + +Fail: + printf ("Failed Conformance Test c99fpcmp\n"); +} diff --git a/Tests/Conformance/c99tgmath.c b/Tests/Conformance/c99tgmath.c new file mode 100644 index 0000000..7548359 --- /dev/null +++ b/Tests/Conformance/c99tgmath.c @@ -0,0 +1,85 @@ +/* + * Test macros (C99). + */ + +#include +#include + +int main(void) { + if (cos(0.0) != 1.0) + goto Fail; + if (copysign(1.0L, -3e10F) != -1.0L) + goto Fail; + + if (sizeof(sin(0.0)) != sizeof(double)) + goto Fail; + if (sizeof(tan(0.5F)) != sizeof(float)) + goto Fail; + if (sizeof(log(2.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(exp(5)) != sizeof(double)) + goto Fail; + if (sizeof(sqrt(7LL)) != sizeof(double)) + goto Fail; + + if (sizeof(fmax(1.0F, 20.0F)) != sizeof(float)) + goto Fail; + if (sizeof(fmin(1.0F, 20.0)) != sizeof(double)) + goto Fail; + if (sizeof(fdim(1.0F, 20.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(hypot(1.0F, 20)) != sizeof(double)) + goto Fail; + if (sizeof(nextafter(1.0F, 20LL)) != sizeof(double)) + goto Fail; + + if (sizeof(fmax(1.0, 20.0F)) != sizeof(double)) + goto Fail; + if (sizeof(fmin(1.0, 20.0)) != sizeof(double)) + goto Fail; + if (sizeof(fdim(1.0, 20.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(hypot(1.0, 20)) != sizeof(double)) + goto Fail; + if (sizeof(nextafter(1.0, 20LL)) != sizeof(double)) + goto Fail; + + if (sizeof(fmax(1.0L, 20.0F)) != sizeof(long double)) + goto Fail; + if (sizeof(fmin(1.0L, 20.0)) != sizeof(long double)) + goto Fail; + if (sizeof(fdim(1.0L, 20.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(hypot(1.0L, 20)) != sizeof(long double)) + goto Fail; + if (sizeof(nextafter(1.0L, 20LL)) != sizeof(long double)) + goto Fail; + + if (sizeof(fmax(1, 20.0F)) != sizeof(double)) + goto Fail; + if (sizeof(fmin(1, 20.0)) != sizeof(double)) + goto Fail; + if (sizeof(fdim(1, 20.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(hypot(1, 20)) != sizeof(double)) + goto Fail; + if (sizeof(nextafter(1, 20LL)) != sizeof(double)) + goto Fail; + + if (sizeof(fmax(1LL, 20.0F)) != sizeof(double)) + goto Fail; + if (sizeof(fmin(1LL, 20.0)) != sizeof(double)) + goto Fail; + if (sizeof(fdim(1LL, 20.0L)) != sizeof(long double)) + goto Fail; + if (sizeof(hypot(1LL, 20)) != sizeof(double)) + goto Fail; + if (sizeof(nextafter(1LL, 20LL)) != sizeof(double)) + goto Fail; + + printf ("Passed Conformance Test c99tgmath\n"); + return 0; + +Fail: + printf ("Failed Conformance Test c99tgmath\n"); +}