]> Savannah Git Hosting - gnulib.git/commitdiff
fenv: Add tests.
authorBruno Haible <bruno@clisp.org>
Fri, 27 Oct 2023 01:46:25 +0000 (03:46 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 27 Oct 2023 01:48:09 +0000 (03:48 +0200)
* tests/test-fenv.c: New file.
* modules/fenv-tests: New file.

ChangeLog
modules/fenv-tests [new file with mode: 0644]
tests/test-fenv.c [new file with mode: 0644]

index b89af7a969348ece0f157e9b1d8fe500de9be6c7..82e7021279ff903f4d7b559d6ceb728daf24fa65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-10-26  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..ec9048e
--- /dev/null
@@ -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 (file)
index 0000000..e0911b7
--- /dev/null
@@ -0,0 +1,69 @@
+/* Test of <fenv.h> 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 <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2023.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <fenv.h>
+
+#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;
+}