eigenmath/erf.cpp

83 lines
1004 B
C++
Raw Permalink Normal View History

2005-07-30 21:37:29 +02:00
//-----------------------------------------------------------------------------
//
// Author : philippe.billet@noos.fr
//
// Error function erf(x)
// erf(-x)=erf(x)
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "defs.h"
static void yyerf(void);
void
eval_erf(void)
{
push(cadr(p1));
eval();
yerf();
}
void
yerf(void)
{
save();
yyerf();
restore();
}
static void
yyerf(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-08-05 21:28:02 +02:00
d = 1.0 - erfc(p1->u.d);
2005-07-30 21:37:29 +02:00
push_double(d);
return;
}
2005-08-05 21:28:02 +02:00
2005-07-30 21:37:29 +02:00
if (isnegativeterm(p1)) {
push_symbol(ERF);
push(p1);
negate();
list(2);
negate();
return;
}
push_symbol(ERF);
push(p1);
list(2);
return;
}
2007-05-08 16:57:30 +02:00
#if SELFTEST
2005-07-30 21:37:29 +02:00
static char *s[] = {
"erf(a)",
"erf(a)",
2005-08-05 21:28:02 +02:00
"erf(0.0) + 1", // add 1 to round off
"1",
"float(erf(0)) + 1", // add 1 to round off
"1",
2005-07-30 21:37:29 +02:00
#if 0
"float(erf(1))",
"0.842701",
#endif
};
void
test_erf(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
2007-05-08 16:57:30 +02:00
#endif