2004-03-03 21:24:06 +01:00
|
|
|
// exp(2 x) - 1
|
|
|
|
// tanh(x) = --------------
|
|
|
|
// exp(2 x) + 1
|
|
|
|
|
2005-06-30 18:03:21 +02:00
|
|
|
#include "stdafx.h"
|
2004-03-03 21:24:06 +01:00
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_tanh(void)
|
|
|
|
{
|
|
|
|
double d;
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
p1 = pop();
|
2006-04-19 01:18:30 +02:00
|
|
|
if (car(p1) == symbol(ARCTANH)) {
|
|
|
|
push(cadr(p1));
|
|
|
|
return;
|
|
|
|
}
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isdouble(p1)) {
|
2004-03-03 21:24:06 +01:00
|
|
|
d = tanh(p1->u.d);
|
|
|
|
if (fabs(d) < 1e-10)
|
|
|
|
d = 0.0;
|
|
|
|
push_double(d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (iszero(p1)) {
|
2004-06-25 22:45:15 +02:00
|
|
|
push(zero);
|
2004-03-03 21:24:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
push_symbol(TANH);
|
|
|
|
push(p1);
|
|
|
|
list(2);
|
|
|
|
}
|
|
|
|
|
2007-05-08 16:57:30 +02:00
|
|
|
#if SELFTEST
|
|
|
|
|
2004-03-03 21:24:06 +01:00
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
"tanh(x)",
|
|
|
|
"tanh(x)",
|
|
|
|
|
|
|
|
"tanh(0)",
|
|
|
|
"0",
|
|
|
|
|
2006-04-19 01:18:30 +02:00
|
|
|
"tanh(arctanh(x))",
|
|
|
|
"x",
|
2004-03-03 21:24:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_tanh(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|
2007-05-08 16:57:30 +02:00
|
|
|
|
|
|
|
#endif
|