2022-01-02 02:54:23 +08:00
|
|
|
/* Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
1999-10-09 01:16:17 +08:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 12:58:11 +08:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
1999-10-09 01:16:17 +08:00
|
|
|
|
|
|
|
The GNU C Library 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
|
2001-07-06 12:58:11 +08:00
|
|
|
Lesser General Public License for more details.
|
1999-10-09 01:16:17 +08:00
|
|
|
|
2001-07-06 12:58:11 +08:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-10 07:18:22 +08:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 13:40:42 +08:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
1999-10-09 01:16:17 +08:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-04-02 19:51:02 +08:00
|
|
|
#include <math-tests.h>
|
|
|
|
|
|
|
|
|
1999-10-09 01:16:17 +08:00
|
|
|
static int errors = 0;
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
check (const char *testname, int result)
|
|
|
|
{
|
|
|
|
if (!result) {
|
|
|
|
printf ("Failure: %s\n", testname);
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 05:30:18 +08:00
|
|
|
#define TEST_FUNC(NAME, FLOAT, SUFFIX, EPSILON, HUGEVAL) \
|
1999-10-09 01:16:17 +08:00
|
|
|
static void \
|
|
|
|
NAME (void) \
|
|
|
|
{ \
|
|
|
|
/* Variables are declared volatile to forbid some compiler \
|
|
|
|
optimizations. */ \
|
2013-03-01 00:12:25 +08:00
|
|
|
volatile FLOAT Inf_var, qNaN_var, zero_var, one_var; \
|
2013-04-02 19:51:02 +08:00
|
|
|
/* A sNaN is only guaranteed to be representable in variables with */ \
|
|
|
|
/* static (or thread-local) storage duration. */ \
|
|
|
|
static volatile FLOAT sNaN_var = __builtin_nans ## SUFFIX (""); \
|
|
|
|
static volatile FLOAT minus_sNaN_var = -__builtin_nans ## SUFFIX (""); \
|
1999-10-09 01:16:17 +08:00
|
|
|
FLOAT x1, x2; \
|
|
|
|
\
|
|
|
|
zero_var = 0.0; \
|
|
|
|
one_var = 1.0; \
|
2013-03-01 05:30:18 +08:00
|
|
|
qNaN_var = __builtin_nan ## SUFFIX (""); \
|
1999-10-09 01:16:17 +08:00
|
|
|
Inf_var = one_var / zero_var; \
|
|
|
|
\
|
|
|
|
(void) &zero_var; \
|
|
|
|
(void) &one_var; \
|
2013-03-01 00:12:25 +08:00
|
|
|
(void) &qNaN_var; \
|
2013-04-02 19:51:02 +08:00
|
|
|
(void) &sNaN_var; \
|
|
|
|
(void) &minus_sNaN_var; \
|
1999-10-09 01:16:17 +08:00
|
|
|
(void) &Inf_var; \
|
|
|
|
\
|
|
|
|
\
|
|
|
|
check (#FLOAT " isinf (inf) == 1", isinf (Inf_var) == 1); \
|
|
|
|
check (#FLOAT " isinf (-inf) == -1", isinf (-Inf_var) == -1); \
|
|
|
|
check (#FLOAT " !isinf (1)", !(isinf (one_var))); \
|
2013-03-01 00:12:25 +08:00
|
|
|
check (#FLOAT " !isinf (qNaN)", !(isinf (qNaN_var))); \
|
2013-04-02 19:51:02 +08:00
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " !isinf (sNaN)", !(isinf (sNaN_var))); \
|
1999-10-09 01:16:17 +08:00
|
|
|
\
|
2013-03-01 00:12:25 +08:00
|
|
|
check (#FLOAT " isnan (qNaN)", isnan (qNaN_var)); \
|
2013-04-02 19:51:02 +08:00
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " isnan (sNaN)", isnan (sNaN_var)); \
|
2013-03-01 00:12:25 +08:00
|
|
|
check (#FLOAT " isnan (-qNaN)", isnan (-qNaN_var)); \
|
2013-04-02 19:51:02 +08:00
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " isnan (-sNaN)", isnan (minus_sNaN_var)); \
|
1999-10-09 01:16:17 +08:00
|
|
|
check (#FLOAT " !isnan (1)", !(isnan (one_var))); \
|
|
|
|
check (#FLOAT " !isnan (inf)", !(isnan (Inf_var))); \
|
|
|
|
\
|
2013-04-02 19:51:02 +08:00
|
|
|
check (#FLOAT " !issignaling (qNaN)", !(issignaling (qNaN_var))); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " issignaling (sNaN)", issignaling (sNaN_var)); \
|
|
|
|
check (#FLOAT " !issignaling (-qNaN)", !(issignaling (-qNaN_var))); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " issignaling (-sNaN)", issignaling (minus_sNaN_var)); \
|
|
|
|
check (#FLOAT " !issignaling (1)", !(issignaling (one_var))); \
|
|
|
|
check (#FLOAT " !issignaling (inf)", !(issignaling (Inf_var))); \
|
|
|
|
\
|
1999-10-09 01:16:17 +08:00
|
|
|
check (#FLOAT " inf == inf", Inf_var == Inf_var); \
|
|
|
|
check (#FLOAT " -inf == -inf", -Inf_var == -Inf_var); \
|
|
|
|
check (#FLOAT " inf != -inf", Inf_var != -Inf_var); \
|
2013-03-01 00:12:25 +08:00
|
|
|
check (#FLOAT " qNaN != qNaN", qNaN_var != qNaN_var); \
|
2013-04-02 19:51:02 +08:00
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " sNaN != sNaN", sNaN_var != sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " qNaN != sNaN", qNaN_var != sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " -sNaN != -sNaN", minus_sNaN_var != minus_sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " sNaN != -sNaN", sNaN_var != minus_sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " qNaN != -sNaN", qNaN_var != minus_sNaN_var); \
|
1999-10-09 01:16:17 +08:00
|
|
|
\
|
|
|
|
/* \
|
|
|
|
the same tests but this time with NAN from <bits/nan.h> \
|
|
|
|
NAN is a double const \
|
|
|
|
*/ \
|
|
|
|
check (#FLOAT " isnan (NAN)", isnan (NAN)); \
|
|
|
|
check (#FLOAT " isnan (-NAN)", isnan (-NAN)); \
|
|
|
|
check (#FLOAT " !isinf (NAN)", !(isinf (NAN))); \
|
|
|
|
check (#FLOAT " !isinf (-NAN)", !(isinf (-NAN))); \
|
|
|
|
check (#FLOAT " NAN != NAN", NAN != NAN); \
|
2013-04-02 19:51:02 +08:00
|
|
|
check (#FLOAT " NAN != qNaN", NAN != qNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " NAN != sNaN", NAN != sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " NAN != -sNaN", NAN != minus_sNaN_var); \
|
1999-10-09 01:16:17 +08:00
|
|
|
\
|
|
|
|
/* \
|
|
|
|
And again with the value returned by the `nan' function. \
|
|
|
|
*/ \
|
2013-03-01 05:30:18 +08:00
|
|
|
check (#FLOAT " isnan (nan (\"\"))", isnan (nan ## SUFFIX (""))); \
|
|
|
|
check (#FLOAT " isnan (-nan (\"\"))", isnan (-nan ## SUFFIX (""))); \
|
|
|
|
check (#FLOAT " !isinf (nan (\"\"))", !(isinf (nan ## SUFFIX ("")))); \
|
|
|
|
check (#FLOAT " !isinf (-nan (\"\"))", !(isinf (-nan ## SUFFIX ("")))); \
|
|
|
|
check (#FLOAT " nan (\"\") != nan (\"\")", \
|
|
|
|
nan ## SUFFIX ("") != nan ## SUFFIX ("")); \
|
2013-04-02 19:51:02 +08:00
|
|
|
check (#FLOAT " nan (\"\") != qNaN", nan ## SUFFIX ("") != qNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " nan (\"\") != sNaN", nan ## SUFFIX ("") != sNaN_var); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
check (#FLOAT " nan (\"\") != -sNaN", \
|
|
|
|
nan ## SUFFIX ("") != minus_sNaN_var); \
|
1999-10-09 01:16:17 +08:00
|
|
|
\
|
|
|
|
/* test if EPSILON is ok */ \
|
|
|
|
x1 = 1.0; \
|
|
|
|
x2 = x1 + EPSILON; \
|
|
|
|
check (#FLOAT " 1 != 1+EPSILON", x1 != x2); \
|
|
|
|
\
|
|
|
|
x1 = 1.0; \
|
|
|
|
x2 = x1 - EPSILON; \
|
|
|
|
check (#FLOAT " 1 != 1-EPSILON", x1 != x2); \
|
|
|
|
\
|
|
|
|
/* test if HUGE_VALx is ok */ \
|
|
|
|
x1 = HUGEVAL; \
|
|
|
|
check (#FLOAT " isinf (HUGE_VALx) == +1", isinf (x1) == +1); \
|
|
|
|
x1 = - HUGEVAL; \
|
|
|
|
check (#FLOAT " isinf (-HUGE_VALx) == -1", isinf (x1) == -1); \
|
|
|
|
}
|
|
|
|
|
2013-05-23 23:31:42 +08:00
|
|
|
#define TEST_CONVERT(NAME, FLOAT, DOUBLE, SUFFIX) \
|
2007-01-16 07:43:04 +08:00
|
|
|
void \
|
|
|
|
NAME (void) \
|
|
|
|
{ \
|
2013-03-01 00:12:25 +08:00
|
|
|
volatile DOUBLE Inf_var, qNaN_var, zero_var, one_var; \
|
2013-04-02 19:51:02 +08:00
|
|
|
/* A sNaN is only guaranteed to be representable in variables with */ \
|
|
|
|
/* static (or thread-local) storage duration. */ \
|
|
|
|
static volatile DOUBLE sNaN_var = __builtin_nans ## SUFFIX (""); \
|
2007-01-16 07:43:04 +08:00
|
|
|
FLOAT x1, x2; \
|
|
|
|
\
|
|
|
|
zero_var = 0.0; \
|
|
|
|
one_var = 1.0; \
|
2013-03-01 05:30:18 +08:00
|
|
|
qNaN_var = __builtin_nan ## SUFFIX (""); \
|
2007-01-16 07:43:04 +08:00
|
|
|
Inf_var = one_var / zero_var; \
|
|
|
|
\
|
2013-03-01 00:12:25 +08:00
|
|
|
(void) &qNaN_var; \
|
2013-04-02 19:51:02 +08:00
|
|
|
(void) &sNaN_var; \
|
2007-01-16 07:43:04 +08:00
|
|
|
(void) &Inf_var; \
|
|
|
|
\
|
2013-03-01 00:12:25 +08:00
|
|
|
x1 = (FLOAT) qNaN_var; \
|
2013-04-02 19:51:02 +08:00
|
|
|
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") qNaN, isnan", isnan (x1)); \
|
|
|
|
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") qNaN, !issignaling", \
|
|
|
|
!issignaling (x1)); \
|
|
|
|
if (SNAN_TESTS (FLOAT)) \
|
|
|
|
{ \
|
|
|
|
x1 = (FLOAT) sNaN_var; \
|
|
|
|
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") sNaN, isnan", isnan (x1)); \
|
|
|
|
if (SNAN_TESTS_TYPE_CAST) \
|
|
|
|
{ \
|
|
|
|
/* Upon type conversion, a sNaN is converted into a qNaN plus an */ \
|
|
|
|
/* INVALID exception (not checked here). */ \
|
|
|
|
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") sNaN, !issignaling", \
|
|
|
|
!issignaling (x1)); \
|
|
|
|
} \
|
|
|
|
} \
|
2007-01-16 07:43:04 +08:00
|
|
|
x2 = (FLOAT) Inf_var; \
|
|
|
|
check (" "#FLOAT" x = ("#FLOAT") ("#DOUBLE") Inf", isinf (x2) != 0); \
|
|
|
|
}
|
|
|
|
|
2013-03-01 05:30:18 +08:00
|
|
|
TEST_FUNC (float_test, float, f, FLT_EPSILON, HUGE_VALF)
|
|
|
|
TEST_FUNC (double_test, double, , DBL_EPSILON, HUGE_VAL)
|
2013-05-23 23:31:42 +08:00
|
|
|
TEST_CONVERT (convert_dfsf_test, float, double, )
|
|
|
|
TEST_CONVERT (convert_sfdf_test, double, float, f)
|
2017-06-29 00:01:20 +08:00
|
|
|
#if LDBL_MANT_DIG > DBL_MANT_DIG
|
2013-03-01 05:30:18 +08:00
|
|
|
TEST_FUNC (ldouble_test, long double, l, LDBL_EPSILON, HUGE_VALL)
|
2013-05-23 23:31:42 +08:00
|
|
|
TEST_CONVERT (convert_tfsf_test, float, long double, l)
|
|
|
|
TEST_CONVERT (convert_sftf_test, long double, float, f)
|
|
|
|
TEST_CONVERT (convert_tfdf_test, double, long double, l)
|
|
|
|
TEST_CONVERT (convert_dftf_test, long double, double, )
|
1999-10-09 01:16:17 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
2007-01-16 07:43:04 +08:00
|
|
|
do_test (void)
|
1999-10-09 01:16:17 +08:00
|
|
|
{
|
|
|
|
float_test ();
|
|
|
|
double_test ();
|
2013-05-23 23:31:42 +08:00
|
|
|
convert_dfsf_test();
|
|
|
|
convert_sfdf_test();
|
1999-10-09 01:16:17 +08:00
|
|
|
|
2017-06-29 00:01:20 +08:00
|
|
|
#if LDBL_MANT_DIG > DBL_MANT_DIG
|
1999-10-09 01:16:17 +08:00
|
|
|
ldouble_test ();
|
2013-05-23 23:31:42 +08:00
|
|
|
convert_tfsf_test();
|
|
|
|
convert_sftf_test();
|
|
|
|
convert_tfdf_test();
|
|
|
|
convert_dftf_test();
|
1999-10-09 01:16:17 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return errors != 0;
|
|
|
|
}
|
2007-01-16 07:43:04 +08:00
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|