Commit 2d91a71b authored by Bruno Haible's avatar Bruno Haible

exp* tests: More tests.

* tests/test-exp.h: New file.
* tests/test-exp.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expf.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expl.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* modules/exp-tests (Files): Add tests/test-exp.h, tests/randomd.c.
(Makefile.am): Add randomd.c to test_exp_SOURCES.
* modules/expf-tests (Files): Add tests/test-exp.h, tests/randomf.c.
(Makefile.am): Add randomf.c to test_expf_SOURCES.
* modules/expl-tests (Files): Add tests/test-exp.h, tests/randoml.c.
(Depends-on): Add 'float'.
(Makefile.am): Add randoml.c to test_expl_SOURCES.
parent 2d0ecbd3
2012-03-05 Bruno Haible <bruno@clisp.org>
exp* tests: More tests.
* tests/test-exp.h: New file.
* tests/test-exp.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expf.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* tests/test-expl.c: Include <float.h> and test-exp.h.
(main): Invoke test_function.
* modules/exp-tests (Files): Add tests/test-exp.h, tests/randomd.c.
(Makefile.am): Add randomd.c to test_exp_SOURCES.
* modules/expf-tests (Files): Add tests/test-exp.h, tests/randomf.c.
(Makefile.am): Add randomf.c to test_expf_SOURCES.
* modules/expl-tests (Files): Add tests/test-exp.h, tests/randoml.c.
(Depends-on): Add 'float'.
(Makefile.am): Add randoml.c to test_expl_SOURCES.
expl: Fix precision of computed result.
* lib/expl.c: Completely rewritten.
* modules/expl (Depends-on): Add isnanl, roundl, ldexpl. Remove floorl.
Files:
tests/test-exp.c
tests/test-exp.h
tests/signature.h
tests/macros.h
tests/randomd.c
Depends-on:
......@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-exp
check_PROGRAMS += test-exp
test_exp_SOURCES = test-exp.c randomd.c
test_exp_LDADD = $(LDADD) @EXP_LIBM@
Files:
tests/test-expf.c
tests/test-exp.h
tests/signature.h
tests/macros.h
tests/randomf.c
Depends-on:
......@@ -10,4 +12,5 @@ configure.ac:
Makefile.am:
TESTS += test-expf
check_PROGRAMS += test-expf
test_expf_SOURCES = test-expf.c randomf.c
test_expf_LDADD = $(LDADD) @EXPF_LIBM@
Files:
tests/test-expl.c
tests/test-exp.h
tests/signature.h
tests/macros.h
tests/randoml.c
Depends-on:
fpucw
float
configure.ac:
Makefile.am:
TESTS += test-expl
check_PROGRAMS += test-expl
test_expl_SOURCES = test-expl.c randoml.c
test_expl_LDADD = $(LDADD) @EXPL_LIBM@
......@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (exp, double, (double));
#include <float.h>
#include "macros.h"
volatile double x;
double y;
#define DOUBLE double
#define L_(literal) literal
#define MANT_DIG DBL_MANT_DIG
#define EXP exp
#define RANDOM randomd
#include "test-exp.h"
int
main ()
......@@ -36,5 +42,7 @@ main ()
y = exp (x);
ASSERT (y >= 1.822118800 && y <= 1.822118801);
test_function ();
return 0;
}
/* Test of exp*() function family.
Copyright (C) 2012 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 <http://www.gnu.org/licenses/>. */
static void
test_function (void)
{
int i;
int j;
const DOUBLE TWO_MANT_DIG =
/* Assume MANT_DIG <= 5 * 31.
Use the identity
n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
(DOUBLE) (1U << ((MANT_DIG - 1) / 5))
* (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
* (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
* (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
* (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
/* Randomized tests. */
{
/* Error bound, in ulps. */
const DOUBLE err_bound =
(sizeof (DOUBLE) == sizeof (long double) ?
#if defined __i386__ && defined __FreeBSD__
/* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
precision in the compiler but 64 bits of precision at runtime. See
<http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>.
The compiler has truncated all 'long double' literals in expl.c to
53 bits of precision. */
L_(1350.0)
#else
L_(4.0)
#endif
: L_(2.0));
for (i = 0; i < SIZEOF (RANDOM); i++)
{
DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
DOUBLE y = EXP (x);
DOUBLE z = EXP (- x);
DOUBLE err = y * z - L_(1.0);
ASSERT (y > L_(0.0));
ASSERT (z > L_(0.0));
ASSERT (err > - err_bound / TWO_MANT_DIG
&& err < err_bound / TWO_MANT_DIG);
}
}
{
/* Error bound, in ulps. */
const DOUBLE err_bound =
(sizeof (DOUBLE) == sizeof (long double) ?
#if defined __i386__ && defined __FreeBSD__
L_(2400.0)
#else
L_(24.0)
#endif
: L_(24.0));
for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
{
DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
DOUBLE y = L_(32.0) * RANDOM[j] - L_(16.0); /* -16.0 <= y <= 16.0 */
DOUBLE z = - x - y;
/* Approximately x + y + z = 0. */
DOUBLE err = EXP (x) * EXP (y) * EXP (z) - L_(1.0);
ASSERT (err > - err_bound / TWO_MANT_DIG
&& err < err_bound / TWO_MANT_DIG);
}
}
}
volatile DOUBLE x;
DOUBLE y;
......@@ -23,10 +23,16 @@
#include "signature.h"
SIGNATURE_CHECK (expf, float, (float));
#include <float.h>
#include "macros.h"
volatile float x;
float y;
#define DOUBLE float
#define L_(literal) literal##f
#define MANT_DIG FLT_MANT_DIG
#define EXP expf
#define RANDOM randomf
#include "test-exp.h"
int
main ()
......@@ -36,5 +42,7 @@ main ()
y = expf (x);
ASSERT (y >= 1.8221188f && y <= 1.8221189f);
test_function ();
return 0;
}
......@@ -23,11 +23,17 @@
#include "signature.h"
SIGNATURE_CHECK (expl, long double, (long double));
#include <float.h>
#include "fpucw.h"
#include "macros.h"
volatile long double x;
long double y;
#define DOUBLE long double
#define L_(literal) literal##L
#define MANT_DIG LDBL_MANT_DIG
#define EXP expl
#define RANDOM randoml
#include "test-exp.h"
int
main ()
......@@ -41,5 +47,7 @@ main ()
y = expl (x);
ASSERT (y >= 1.822118800L && y <= 1.822118801L);
test_function ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment