/* specfunc/test_sf.c
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2004 Gerard Jungman
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/* Author: G. Jungman */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_ieee_utils.h>
#include <gsl/gsl_test.h>
#include <gsl/gsl_sf.h>
#include "test_sf.h"
double
test_sf_frac_diff(double x1, double x2)
{
if(x1 == 0.0 && x2 == 0.0) {
return 0.0;
}
else if (x1 == 0.0) {
return fabs(x2);
} else if(x1 <= DBL_MAX && x2 <= DBL_MAX && (x1 + x2 != 0.0)) {
return fabs((x1-x2)/(x1+x2));
}
else {
return 1.0;
}
}
/* Check a result against a given value and tolerance.
*/
int
test_sf_check_result(char * message_buff, gsl_sf_result r, double val, double tol)
{
int s = 0;
double f = 0;
if (gsl_isnan(r.val) || gsl_isnan(val))
{
s = (gsl_isnan(r.val) != gsl_isnan(val)) ? TEST_SF_INCONS : s;
}
else if (gsl_isinf(r.val) || gsl_isinf(val))
{
s = (gsl_isinf(r.val) != gsl_isinf(val)) ? TEST_SF_INCONS : s;
}
else
{
f = test_sf_frac_diff(val, r.val);
if(fabs(val - r.val) > 2.0 * TEST_SIGMA * r.err) s |= TEST_SF_INCONS;
if(r.err < 0.0) s |= TEST_SF_ERRNEG;
if(gsl_isinf(r.err)) s |= TEST_SF_ERRBAD;
if(f > TEST_FACTOR * tol) s |= TEST_SF_TOLBAD;
}
if(s != 0) {
char buff[2048];
sprintf(buff, " expected: %20.16g\n", val);
strcat(message_buff, buff);
sprintf(buff, " obtained: %20.16g +/- %.16g (rel=%g)\n", r.val, r.err, r.err/(fabs(r.val) + r.err));
strcat(message_buff, buff);
sprintf(buff, " fracdiff: %20.16g\n", f);
strcat(message_buff, buff);
}
if(s & TEST_SF_INCONS) {
strcat(message_buff, " value/expected not consistent within reported error\n");
}
if(s & TEST_SF_ERRNEG) {
strcat(message_buff, " reported error negative\n");
}
if(s & TEST_SF_ERRBAD) {
strcat(message_buff, " reported error is bad\n");
}
if(s & TEST_SF_TOLBAD) {
strcat(message_buff, " value not within tolerance of expected value\n");
}
return s;
}
int
test_sf_check_val(char * message_buff, double rval, double val, double tol)
{
int s = 0;
double f = test_sf_frac_diff(val, rval);
if(f > TEST_FACTOR * tol) s |= TEST_SF_TOLBAD;
if(s != 0) {
char buff[2048];
sprintf(buff, " expected: %20.16g\n", val);
strcat(message_buff, buff);
sprintf(buff, " obtained: %20.16g\n", rval);
strcat(message_buff, buff);
sprintf(buff, " fracdiff: %20.16g\n", f);
strcat(message_buff, buff);
}
if(s & TEST_SF_TOLBAD) {
strcat(message_buff, " value not within tolerance of expected value\n");
}
return s;
}
/* Relax the condition on the agreement and on the usefulness
* of the error estimate.
*/
int
test_sf_check_result_relax(char * message_buff, gsl_sf_result r, double val, double tol)
{
int s = 0;
double f = test_sf_frac_diff(val, r.val);
if(f > GSL_MAX_DBL(TEST_SNGL, TEST_FACTOR * tol)) s |= TEST_SF_INCONS;
if(r.err < 0.0) s |= TEST_SF_ERRNEG;
if(gsl_isinf(r.err)) s |= TEST_SF_ERRBAD;
if(f > TEST_FACTOR * tol) s |= TEST_SF_TOLBAD;
if(s != 0) {
char buff[2048];
sprintf(buff, " expected: %20.16g\n", val);
strcat(message_buff, buff);
sprintf(buff, " obtained: %20.16g +/- %.16g (rel=%g)\n", r.val, r.err, r.err/(fabs(r.val) + r.err));
strcat(message_buff, buff);
sprintf(buff, " fracdiff: %20.16g\n", f);
strcat(message_buff, buff);
}
if(s & TEST_SF_INCONS) {
strcat(message_buff, " value/expected not consistent MAX(tol,SINGLE_PREC)\n");
}
if(s & TEST_SF_ERRNEG) {
strcat(message_buff, " reported error negative\n");
}
if(s & TEST_SF_ERRBAD) {
strcat(message_buff, " reported error is bad\n");
}
if(s & TEST_SF_TOLBAD) {
strcat(message_buff, " value not within tolerance of expected value\n");
}
return s;
}
/* Check a return value.
*/
int
test_sf_check_return(char * message_buff, int val_return, int expected_return)
{
if(val_return != expected_return) {
char buff[256];
sprintf(buff, " unexpected return code: %d\n", val_return);
strcat(message_buff, buff);
return TEST_SF_RETBAD;
}
else {
return 0;
}
}
int
test_sf (gsl_sf_result r, double val_in, double tol, int status,
int expect_return, const char * desc)
{
char message_buff[4096];
int local_s = 0;
message_buff[0] = '\0';
local_s |= test_sf_check_result(message_buff, r, val_in, tol);
local_s |= test_sf_check_return(message_buff, status, expect_return);
gsl_test(local_s, desc);
if(local_s != 0) {
/* printf(" %s %d\n", __FILE__, __LINE__); */
printf("%s", message_buff);
printf(" %22.18g %22.18g\n", r.val, r.err);
}
return local_s;
}
int
test_sf_val (double val, double val_in, double tol, const char * desc)
{
char message_buff[4096];
int local_s = 0;
message_buff[0] = '\0';
local_s |= test_sf_check_val(message_buff, val, val_in, tol);
gsl_test(local_s, desc);
if(local_s != 0) {
/* printf(" %s %d\n", __FILE__, __LINE__); */
printf("%s", message_buff);
printf(" %22.18g\n", val);
}
return local_s;
}
int
test_sf_rlx (gsl_sf_result r, double val_in, double tol, int status,
int expect_return, const char * desc)
{
char message_buff[4096];
int local_s = 0;
message_buff[0] = '\0';
local_s |= test_sf_check_result_relax(message_buff, r, val_in, tol);
local_s |= test_sf_check_return(message_buff, status, expect_return);
gsl_test(local_s, desc);
if(local_s != 0) {
/* printf(" %s %d\n", __FILE__, __LINE__); */
printf("%s", message_buff);
printf(" %22.18g %22.18g\n", r.val, r.err);
}
return local_s;
}
int
test_sf_2 (gsl_sf_result r1, double val1, double tol1,
gsl_sf_result r2, double val2, double tol2,
int status, int expect_return, const char * desc)
{
char message_buff[4096];
int local_s = 0;
message_buff[0] = '\0';
local_s |= test_sf_check_result(message_buff, r1, val1, tol1);
local_s |= test_sf_check_result(message_buff, r2, val2, tol2);
local_s |= test_sf_check_return(message_buff, status, expect_return);
gsl_test(local_s, desc);
if(local_s != 0) {
/* printf(" %s %d\n", __FILE__, __LINE__); */
printf("%s", message_buff);
printf(" %22.18g %22.18g\n", r1.val, r1.err);
printf(" %22.18g %22.18g\n", r2.val, r2.err);
}
return local_s;
}
int
test_sf_sgn (gsl_sf_result r, double sgn, double val_in, double tol, double expect_sgn, int status,
int expect_return, const char * desc)
{
char message_buff[4096];
gsl_sf_result local_r;
int local_s = 0;
message_buff[0] = '\0';
local_r.val = sgn;
local_r.err = 0.0;
local_s |= test_sf_check_result(message_buff, r, val_in, tol);
local_s |= test_sf_check_result(message_buff, local_r, expect_sgn, 0.0);
local_s |= test_sf_check_return(message_buff, status, expect_return);
gsl_test(local_s, desc);
if(local_s != 0) {
/* printf(" %s %d\n", __FILE__, __LINE__); */
printf("%s", message_buff);
printf(" %22.18g %22
没有合适的资源?快使用搜索试试~ 我知道了~
gsl-1.9.tar.gz
4星 · 超过85%的资源 需积分: 10 21 下载量 13 浏览量
2009-04-01
12:45:35
上传
评论
收藏 2.46MB GZ 举报
温馨提示
共1668个文件
c:947个
h:331个
texi:78个
GSL类库 The GNU Scientific Library (GSL) is a numerical library for C and C++ programmers. It is free software under the GNU General Public License.
资源推荐
资源详情
资源评论
收起资源包目录
gsl-1.9.tar.gz (1668个子文件)
gsl-histogram.1 1KB
gsl-config.1 1KB
gsl-randist.1 1KB
gsl.3 1KB
configure.ac 11KB
Makefile.am 4KB
Makefile.am 3KB
Makefile.am 2KB
Makefile.am 2KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1KB
Makefile.am 1009B
Makefile.am 968B
Makefile.am 901B
Makefile.am 862B
Makefile.am 805B
Makefile.am 805B
Makefile.am 800B
Makefile.am 759B
Makefile.am 732B
Makefile.am 729B
Makefile.am 718B
Makefile.am 710B
Makefile.am 699B
Makefile.am 680B
Makefile.am 670B
Makefile.am 650B
Makefile.am 575B
Makefile.am 555B
Makefile.am 549B
Makefile.am 539B
Makefile.am 518B
Makefile.am 509B
Makefile.am 486B
Makefile.am 479B
Makefile.am 433B
Makefile.am 428B
Makefile.am 400B
Makefile.am 387B
Makefile.am 382B
Makefile.am 378B
Makefile.am 366B
Makefile.am 352B
Makefile.am 346B
Makefile.am 306B
Makefile.am 241B
Makefile.am 193B
AUTHORS 1KB
fftalgorithms.bib 6KB
BUGS 6KB
test_sf.c 141KB
test_trsm.c 123KB
test_trmm.c 123KB
test_auto.c 121KB
test.c 99KB
test.c 82KB
test.c 68KB
hyperg_1F1.c 60KB
gamma.c 59KB
blas.c 56KB
test_tbsv.c 53KB
test_tbmv.c 53KB
test_rotg.c 47KB
nonsymmv.c 44KB
hyperg_U.c 44KB
legendre_con.c 42KB
test_tpsv.c 42KB
test_tpmv.c 42KB
test_gemm.c 41KB
test_hyperg.c 41KB
test_bessel.c 40KB
test_trsv.c 39KB
test_trmv.c 39KB
coulomb.c 39KB
test.c 38KB
test_legendre.c 35KB
test_rotm.c 35KB
fermi_dirac.c 34KB
zeta.c 32KB
bessel_olver.c 31KB
bessel_zero.c 28KB
hyperg_2F1.c 27KB
bessel.c 26KB
test_nist.c 26KB
test_gamma.c 25KB
test.c 25KB
airy_der.c 25KB
psi.c 24KB
airy.c 23KB
math.c 23KB
mathieu_charv.c 22KB
francis.c 22KB
vegas.c 21KB
legendre_poly.c 21KB
共 1668 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
- bjbzcg2013-03-01版本挺新,可以用
daocha
- 粉丝: 22
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功