eigenmath/erfc.cpp

89 lines
1.2 KiB
C++
Raw Permalink Normal View History

2005-07-30 21:37:29 +02:00
//-----------------------------------------------------------------------------
//
// Author : philippe.billet@noos.fr
//
// erfc(x)
2005-08-05 21:28:02 +02:00
//
// GW Added erfc() from Numerical Recipes in C
2005-07-30 21:37:29 +02:00
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "defs.h"
static void yyerfc(void);
void
eval_erfc(void)
{
push(cadr(p1));
eval();
yerfc();
}
void
yerfc(void)
{
save();
yyerfc();
restore();
}
static void
yyerfc(void)
{
2005-08-05 21:28:02 +02:00
double d;
2005-07-30 21:37:29 +02:00
p1 = pop();
2005-08-05 21:28:02 +02:00
2005-08-06 22:57:37 +02:00
if (isdouble(p1)) {
2005-07-30 21:37:29 +02:00
d = erfc(p1->u.d);
push_double(d);
return;
}
2005-08-05 21:28:02 +02:00
2005-07-30 21:37:29 +02:00
push_symbol(ERFC);
push(p1);
list(2);
return;
}
2005-08-05 21:28:02 +02:00
// from Numerical Recipes in C
#ifndef LINUX
double
erfc(double x)
{
double t, z, ans;
z = fabs(x);
t = 1.0 / (1.0 + 0.5 * z);
ans=t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
t*(-0.82215223+t*0.17087277)))))))));
return x >= 0.0 ? ans : 2.0-ans;
}
#endif
2005-07-30 21:37:29 +02:00
static char *s[] = {
"erfc(a)",
"erfc(a)",
2005-08-05 21:28:02 +02:00
"erfc(0.0)",
"1",
2005-07-30 21:37:29 +02:00
"float(erfc(0))",
"1",
2005-08-05 21:28:02 +02:00
#if 0
2005-07-30 21:37:29 +02:00
"float(erfc(1))",
"0.157299",
#endif
};
void
test_erfc(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}