Use a pre-calculated value as expected result, instead of

comparing it in a mathematical formula.
PR lib/46434 (and see also 46433).
This commit is contained in:
isaki 2013-04-09 12:11:04 +00:00
parent ffc77545dc
commit 0c8b5b215f
5 changed files with 204 additions and 165 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_acos.c,v 1.3 2012/03/23 23:45:31 matt Exp $ */
/* $NetBSD: t_acos.c,v 1.4 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -32,6 +32,20 @@
#include <atf-c.h>
#include <math.h>
static const struct {
double x;
double y;
} values[] = {
{ -1, M_PI, },
{ -0.99, 3.000053180265366, },
{ -0.5, 2.094395102393195, },
{ -0.1, 1.670963747956456, },
{ 0, M_PI / 2, },
{ 0.1, 1.470628905633337, },
{ 0.5, 1.047197551196598, },
{ 0.99, 0.141539473324427, },
};
/*
* acos(3)
*/
@ -119,28 +133,25 @@ ATF_TC_BODY(acos_range, tc)
#endif
}
ATF_TC(acos_cos);
ATF_TC_HEAD(acos_cos, tc)
ATF_TC(acos_inrange);
ATF_TC_HEAD(acos_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test acos(cos(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test acos(x) for some values");
}
ATF_TC_BODY(acos_cos, tc)
ATF_TC_BODY(acos_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const double eps = 1.0e-15;
double x;
double y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = acos(cos(x[i]));
if (fabs(y - x[i]) > eps)
atf_tc_fail_nonfatal(
"acos(cos(%0.03f)) != %0.03f (eps=%0.03e)",
x[i], x[i], fabs(y - x[i]));
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
if (fabs(acos(x) - y) > eps)
atf_tc_fail_nonfatal("acos(%g) != %g", x, y);
}
#endif
}
@ -232,28 +243,25 @@ ATF_TC_BODY(acosf_range, tc)
#endif
}
ATF_TC(acosf_cosf);
ATF_TC_HEAD(acosf_cosf, tc)
ATF_TC(acosf_inrange);
ATF_TC_HEAD(acosf_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test acosf(cosf(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test acosf(x) for some values");
}
ATF_TC_BODY(acosf_cosf, tc)
ATF_TC_BODY(acosf_inrange, tc)
{
#ifndef __vax__
const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const float eps = 1.0e-5;
float x;
float y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = acosf(cosf(x[i]));
if (fabsf(y - x[i]) > eps)
atf_tc_fail_nonfatal(
"acosf(cosf(%0.03f)) != %0.03f (eps=%0.03e)",
x[i], x[i], fabs(y - x[i]));
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
if (fabsf(acosf(x) - y) > eps)
atf_tc_fail_nonfatal("acosf(%g) != %g", x, y);
}
#endif
}
@ -266,14 +274,14 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, acos_inf_pos);
ATF_TP_ADD_TC(tp, acos_one_pos);
ATF_TP_ADD_TC(tp, acos_range);
ATF_TP_ADD_TC(tp, acos_cos);
ATF_TP_ADD_TC(tp, acos_inrange);
ATF_TP_ADD_TC(tp, acosf_nan);
ATF_TP_ADD_TC(tp, acosf_inf_neg);
ATF_TP_ADD_TC(tp, acosf_inf_pos);
ATF_TP_ADD_TC(tp, acosf_one_pos);
ATF_TP_ADD_TC(tp, acosf_range);
ATF_TP_ADD_TC(tp, acosf_cosf);
ATF_TP_ADD_TC(tp, acosf_inrange);
return atf_no_error();
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_asin.c,v 1.1 2011/09/17 18:08:35 jruoho Exp $ */
/* $NetBSD: t_asin.c,v 1.2 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -32,6 +32,20 @@
#include <atf-c.h>
#include <math.h>
static const struct {
double x;
double y;
} values[] = {
{ -1.0, -M_PI / 2, },
{ -0.9, -1.119769514998634, },
{ -0.5, -M_PI / 6, },
{ -0.1, -0.1001674211615598, },
{ 0.1, 0.1001674211615598, },
{ 0.5, M_PI / 6, },
{ 0.9, 1.119769514998634, },
{ 1.0, M_PI / 2, },
};
/*
* asin(3)
*/
@ -103,27 +117,24 @@ ATF_TC_BODY(asin_range, tc)
#endif
}
ATF_TC(asin_sin);
ATF_TC_HEAD(asin_sin, tc)
ATF_TC(asin_inrange);
ATF_TC_HEAD(asin_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test asin(sin(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test asin(x) for some values");
}
ATF_TC_BODY(asin_sin, tc)
ATF_TC_BODY(asin_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const double eps = 1.0e-40;
const double eps = 1.0e-15;
double y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = asin(sin(x[i]));
if (fabs(y - x[i]) > eps)
atf_tc_fail_nonfatal("asin(sin(%0.03f)) != %0.03f",
x[i], x[i]);
for (i = 0; i < __arraycount(values); i++) {
y = asin(values[i].x);
if (fabs(y - values[i].y) > eps)
atf_tc_fail_nonfatal("asin(%g) != %g",
values[i].x, values[i].y);
}
#endif
}
@ -233,27 +244,25 @@ ATF_TC_BODY(asinf_range, tc)
#endif
}
ATF_TC(asinf_sinf);
ATF_TC_HEAD(asinf_sinf, tc)
ATF_TC(asinf_inrange);
ATF_TC_HEAD(asinf_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test asinf(sinf(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test asinf(x) for some values");
}
ATF_TC_BODY(asinf_sinf, tc)
ATF_TC_BODY(asinf_inrange, tc)
{
#ifndef __vax__
const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const float eps = 1.0e-6;
float x;
float y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = asinf(sinf(x[i]));
if (fabsf(y - x[i]) > eps)
atf_tc_fail_nonfatal("asinf(sinf(%0.03f)) != %0.03f",
x[i], x[i]);
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
if (fabs(asinf(x) - y) > eps)
atf_tc_fail_nonfatal("asinf(%g) != %g", x, y);
}
#endif
}
@ -299,7 +308,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, asin_inf_neg);
ATF_TP_ADD_TC(tp, asin_inf_pos);
ATF_TP_ADD_TC(tp, asin_range);
ATF_TP_ADD_TC(tp, asin_sin);
ATF_TP_ADD_TC(tp, asin_inrange);
ATF_TP_ADD_TC(tp, asin_zero_neg);
ATF_TP_ADD_TC(tp, asin_zero_pos);
@ -307,7 +316,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, asinf_inf_neg);
ATF_TP_ADD_TC(tp, asinf_inf_pos);
ATF_TP_ADD_TC(tp, asinf_range);
ATF_TP_ADD_TC(tp, asinf_sinf);
ATF_TP_ADD_TC(tp, asinf_inrange);
ATF_TP_ADD_TC(tp, asinf_zero_neg);
ATF_TP_ADD_TC(tp, asinf_zero_pos);

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_atan.c,v 1.7 2013/03/21 02:10:52 isaki Exp $ */
/* $NetBSD: t_atan.c,v 1.8 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -35,6 +35,20 @@
#include <stdlib.h>
#include <string.h>
static const struct {
double x;
double y;
} values[] = {
{ -100, -1.560796660108231, },
{ -10, -1.471127674303735, },
{ -1, -M_PI / 4, },
{ -0.1, -0.09966865249116204, },
{ 0.1, 0.09966865249116204, },
{ 1, M_PI / 4, },
{ 10, 1.471127674303735, },
{ 100, 1.560796660108231, },
};
/*
* atan(3)
*/
@ -88,27 +102,22 @@ ATF_TC_BODY(atan_inf_pos, tc)
#endif
}
ATF_TC(atan_tan);
ATF_TC_HEAD(atan_tan, tc)
ATF_TC(atan_inrange);
ATF_TC_HEAD(atan_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test atan(tan(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test atan(x) for some values");
}
ATF_TC_BODY(atan_tan, tc)
ATF_TC_BODY(atan_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 };
const double eps = 1.0e-15;
double y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = atan(tan(x[i]));
if (fabs(y - x[i]) > eps)
atf_tc_fail_nonfatal("atan(tan(%0.03f)) != %0.03f",
x[i], x[i]);
for (i = 0; i < __arraycount(values); i++) {
if (fabs(atan(values[i].x) - values[i].y) > eps)
atf_tc_fail_nonfatal("atan(%g) != %g",
values[i].x, values[i].y);
}
#endif
}
@ -200,27 +209,25 @@ ATF_TC_BODY(atanf_inf_pos, tc)
#endif
}
ATF_TC(atanf_tanf);
ATF_TC_HEAD(atanf_tanf, tc)
ATF_TC(atanf_inrange);
ATF_TC_HEAD(atanf_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test atanf(tanf(x)) == x");
atf_tc_set_md_var(tc, "descr", "Test atanf(x) for some values");
}
ATF_TC_BODY(atanf_tanf, tc)
ATF_TC_BODY(atanf_inrange, tc)
{
#ifndef __vax__
const float x[] = { 0.0, 1.0, M_PI / 3, M_PI / 6 };
const float eps = 1.0e-7;
float x;
float y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
y = atanf(tanf(x[i]));
if (fabsf(y - x[i]) > eps)
atf_tc_fail_nonfatal("atanf(tanf(%0.03f)) != %0.03f",
x[i], x[i]);
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
if (fabs(atanf(x) - y) > eps)
atf_tc_fail_nonfatal("atan(%g) != %g", x, y);
}
#endif
}
@ -265,14 +272,14 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, atan_nan);
ATF_TP_ADD_TC(tp, atan_inf_neg);
ATF_TP_ADD_TC(tp, atan_inf_pos);
ATF_TP_ADD_TC(tp, atan_tan);
ATF_TP_ADD_TC(tp, atan_inrange);
ATF_TP_ADD_TC(tp, atan_zero_neg);
ATF_TP_ADD_TC(tp, atan_zero_pos);
ATF_TP_ADD_TC(tp, atanf_nan);
ATF_TP_ADD_TC(tp, atanf_inf_neg);
ATF_TP_ADD_TC(tp, atanf_inf_pos);
ATF_TP_ADD_TC(tp, atanf_tanf);
ATF_TP_ADD_TC(tp, atanf_inrange);
ATF_TP_ADD_TC(tp, atanf_zero_neg);
ATF_TP_ADD_TC(tp, atanf_zero_pos);

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_cosh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $ */
/* $NetBSD: t_cosh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,41 +29,54 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_cosh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $");
__RCSID("$NetBSD: t_cosh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $");
#include <atf-c.h>
#include <math.h>
#include <stdio.h>
static const struct {
double x;
double y;
double e;
} values[] = {
{ -10, 11013.23292010332, 1e4, },
{ -2, 3.762195691083631, 1, },
{ -1, 1.543080634815244, 1, },
{ -0.05, 1.001250260438369, 1, },
{ -0.001, 1.000000500000042, 1, },
{ 0, 1, 1, },
{ 0.001, 1.000000500000042, 1, },
{ 0.05, 1.001250260438369, 1, },
{ 1, 1.543080634815244, 1, },
{ 2, 3.762195691083631, 1, },
{ 10, 11013.23292010332, 1e4, },
};
/*
* cosh(3)
*/
ATF_TC(cosh_def);
ATF_TC_HEAD(cosh_def, tc)
ATF_TC(cosh_inrange);
ATF_TC_HEAD(cosh_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test the definition of cosh(3)");
atf_tc_set_md_var(tc, "descr", "cosh(x) for some values");
}
ATF_TC_BODY(cosh_def, tc)
ATF_TC_BODY(cosh_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
const double eps = 1.0e-8;
double y, z;
double eps;
double x;
double y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
eps = 1e-15 * values[i].e;
y = cosh(x[i]);
z = (exp(x[i]) + exp(-x[i])) / 2;
(void)fprintf(stderr,
"cosh(%0.03f) = %f\n(exp(%0.03f) + "
"exp(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
if (fabs(y - z) > eps)
atf_tc_fail_nonfatal("cosh(%0.03f) != %0.03f\n",
x[i], z);
if (fabs(cosh(x) - y) > eps)
atf_tc_fail_nonfatal("cosh(%g) != %g\n", x, y);
}
#endif
}
@ -153,32 +166,27 @@ ATF_TC_BODY(cosh_zero_pos, tc)
/*
* coshf(3)
*/
ATF_TC(coshf_def);
ATF_TC_HEAD(coshf_def, tc)
ATF_TC(coshf_inrange);
ATF_TC_HEAD(coshf_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test the definition of coshf(3)");
atf_tc_set_md_var(tc, "descr", "coshf(x) for some values");
}
ATF_TC_BODY(coshf_def, tc)
ATF_TC_BODY(coshf_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
const float eps = 1.0e-3;
float y, z;
float eps;
float x;
float y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
eps = 1e-6 * values[i].e;
y = coshf(x[i]);
z = (expf(x[i]) + expf(-x[i])) / 2;
(void)fprintf(stderr,
"coshf(%0.03f) = %f\n(expf(%0.03f) + "
"expf(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
if (fabsf(y - z) > eps)
atf_tc_fail_nonfatal("coshf(%0.03f) != %0.03f\n",
x[i], z);
if (fabsf(coshf(x) - y) > eps)
atf_tc_fail_nonfatal("coshf(%g) != %g\n", x, y);
}
#endif
}
@ -268,14 +276,14 @@ ATF_TC_BODY(coshf_zero_pos, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, cosh_def);
ATF_TP_ADD_TC(tp, cosh_inrange);
ATF_TP_ADD_TC(tp, cosh_nan);
ATF_TP_ADD_TC(tp, cosh_inf_neg);
ATF_TP_ADD_TC(tp, cosh_inf_pos);
ATF_TP_ADD_TC(tp, cosh_zero_neg);
ATF_TP_ADD_TC(tp, cosh_zero_pos);
ATF_TP_ADD_TC(tp, coshf_def);
ATF_TP_ADD_TC(tp, coshf_inrange);
ATF_TP_ADD_TC(tp, coshf_nan);
ATF_TP_ADD_TC(tp, coshf_inf_neg);
ATF_TP_ADD_TC(tp, coshf_inf_pos);

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_sinh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $ */
/* $NetBSD: t_sinh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@ -29,41 +29,53 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_sinh.c,v 1.4 2011/10/18 14:16:42 jruoho Exp $");
__RCSID("$NetBSD: t_sinh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $");
#include <atf-c.h>
#include <math.h>
#include <stdio.h>
static const struct {
double x;
double y;
double e;
} values[] = {
{ -10, -11013.23287470339, 1e4, },
{ -2, -3.626860407847019, 1, },
{ -1, -1.175201193643801, 1, },
{ -0.05, -0.050020835937655, 1, },
{ -0.001,-0.001000000166667, 1, },
{ 0.001, 0.001000000166667, 1, },
{ 0.05, 0.050020835937655, 1, },
{ 1, 1.175201193643801, 1, },
{ 2, 3.626860407847019, 1, },
{ 10, 11013.23287470339, 1e4, },
};
/*
* sinh(3)
*/
ATF_TC(sinh_def);
ATF_TC_HEAD(sinh_def, tc)
ATF_TC(sinh_inrange);
ATF_TC_HEAD(sinh_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test the definition of sinh(3)");
atf_tc_set_md_var(tc, "descr", "sinh(x) for some values");
}
ATF_TC_BODY(sinh_def, tc)
ATF_TC_BODY(sinh_inrange, tc)
{
#ifndef __vax__
const double x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
const double eps = 1.0e-4;
double y, z;
double eps;
double x;
double y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
eps = 1e-15 * values[i].e;
y = sinh(x[i]);
z = (exp(x[i]) - exp(-x[i])) / 2;
(void)fprintf(stderr,
"sinh(%0.03f) = %f\n(exp(%0.03f) - "
"exp(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
if (fabs(y - z) > eps)
atf_tc_fail_nonfatal("sinh(%0.03f) != %0.03f\n",
x[i], z);
if (fabs(sinh(x) - y) > eps)
atf_tc_fail_nonfatal("sinh(%g) != %g\n", x, y);
}
#endif
}
@ -155,32 +167,27 @@ ATF_TC_BODY(sinh_zero_pos, tc)
/*
* sinhf(3)
*/
ATF_TC(sinhf_def);
ATF_TC_HEAD(sinhf_def, tc)
ATF_TC(sinhf_inrange);
ATF_TC_HEAD(sinhf_inrange, tc)
{
atf_tc_set_md_var(tc, "descr", "Test the definition of sinhf(3)");
atf_tc_set_md_var(tc, "descr", "sinhf(x) for some values");
}
ATF_TC_BODY(sinhf_def, tc)
ATF_TC_BODY(sinhf_inrange, tc)
{
#ifndef __vax__
const float x[] = { 0.005, 0.05, 0.0, 1.0, 10.0, 20.0 };
const float eps = 1.0e-2;
float y, z;
float eps;
float x;
float y;
size_t i;
for (i = 0; i < __arraycount(x); i++) {
for (i = 0; i < __arraycount(values); i++) {
x = values[i].x;
y = values[i].y;
eps = 1e-6 * values[i].e;
y = sinhf(x[i]);
z = (expf(x[i]) - expf(-x[i])) / 2;
(void)fprintf(stderr,
"sinhf(%0.03f) = %f\n(expf(%0.03f) - "
"expf(-%0.03f)) / 2 = %f\n", x[i], y, x[i], x[i], z);
if (fabsf(y - z) > eps)
atf_tc_fail_nonfatal("sinhf(%0.03f) != %0.03f\n",
x[i], z);
if (fabsf(sinhf(x) - y) > eps)
atf_tc_fail_nonfatal("sinhf(%g) != %g\n", x, y);
}
#endif
}
@ -272,14 +279,14 @@ ATF_TC_BODY(sinhf_zero_pos, tc)
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, sinh_def);
ATF_TP_ADD_TC(tp, sinh_inrange);
ATF_TP_ADD_TC(tp, sinh_nan);
ATF_TP_ADD_TC(tp, sinh_inf_neg);
ATF_TP_ADD_TC(tp, sinh_inf_pos);
ATF_TP_ADD_TC(tp, sinh_zero_neg);
ATF_TP_ADD_TC(tp, sinh_zero_pos);
ATF_TP_ADD_TC(tp, sinhf_def);
ATF_TP_ADD_TC(tp, sinhf_inrange);
ATF_TP_ADD_TC(tp, sinhf_nan);
ATF_TP_ADD_TC(tp, sinhf_inf_neg);
ATF_TP_ADD_TC(tp, sinhf_inf_pos);