From 3aac95314ccc57d53380e8c69922a6d33203bc5f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 27 Oct 2023 03:46:25 +0200 Subject: [PATCH] fenv: Add tests. * tests/test-fenv.c: New file. * modules/fenv-tests: New file. --- ChangeLog | 4 +++ modules/fenv-tests | 11 ++++++++ tests/test-fenv.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 modules/fenv-tests create mode 100644 tests/test-fenv.c diff --git a/ChangeLog b/ChangeLog index b89af7a969..82e7021279 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2023-10-26 Bruno Haible + fenv: Add tests. + * tests/test-fenv.c: New file. + * modules/fenv-tests: New file. + fenv: New module. * lib/fenv.in.h: New file, based on glibc. * m4/fenv_h.m4: New file. diff --git a/modules/fenv-tests b/modules/fenv-tests new file mode 100644 index 0000000000..ec9048e202 --- /dev/null +++ b/modules/fenv-tests @@ -0,0 +1,11 @@ +Files: +tests/test-fenv.c + +Depends-on: +verify + +configure.ac: + +Makefile.am: +TESTS += test-fenv +check_PROGRAMS += test-fenv diff --git a/tests/test-fenv.c b/tests/test-fenv.c new file mode 100644 index 0000000000..e0911b7839 --- /dev/null +++ b/tests/test-fenv.c @@ -0,0 +1,69 @@ +/* Test of substitute. + Copyright (C) 2023 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2023. */ + +#include + +/* Specification. */ +#include + +#include "verify.h" + +/* Check that the various FE_* macros are defined. */ +int r[] = + { +#ifdef FE_DOWNWARD + FE_DOWNWARD, +#endif +#ifdef FE_UPWARD + FE_UPWARD, +#endif +#ifdef FE_TOWARDZERO + FE_TOWARDZERO, +#endif + FE_TONEAREST + }; +int e[] = { FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW }; + +/* Check that the types are all defined. */ +fenv_t t1; +fexcept_t t2; + +/* On many platforms, other FE_* constants are included in FE_ALL_EXCEPT, + therefore in general + FE_ALL_EXCEPT == (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + does not hold. */ +verify (((FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) + & ~FE_ALL_EXCEPT) + == 0); + +int +main (void) +{ + /* Ensure no overlap in FE_*. */ + switch (FE_INVALID) + { + case FE_DIVBYZERO: + case FE_INEXACT: + case FE_INVALID: + case FE_OVERFLOW: + case FE_UNDERFLOW: + ; + } + + return 0; +} -- 2.39.5