Add tests for fp comparison macros and type-generic math macros.

This commit is contained in:
Stephen Heumann 2022-01-09 16:51:40 -06:00
parent d0514c5dc4
commit 8c5fba684c
3 changed files with 179 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,92 @@
/*
* Test floating-point comparison macros (C99).
*/
#include <fenv.h>
#include <math.h>
#include <stdio.h>
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");
}

View File

@ -0,0 +1,85 @@
/*
* Test <tgmath.h> macros (C99).
*/
#include <tgmath.h>
#include <stdio.h>
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");
}