2004-03-03 21:24:06 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
2005-06-30 18:03:21 +02:00
|
|
|
static void ytangent(void);
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
eval_tan(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
tangent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tangent(void)
|
|
|
|
{
|
|
|
|
save();
|
2005-06-30 18:03:21 +02:00
|
|
|
ytangent();
|
2004-03-03 21:24:06 +01:00
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-06-30 18:03:21 +02:00
|
|
|
ytangent(void)
|
2004-03-03 21:24:06 +01:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
double d;
|
|
|
|
|
|
|
|
p1 = pop();
|
|
|
|
|
2005-08-06 22:57:37 +02:00
|
|
|
if (isdouble(p1)) {
|
2004-03-03 21:24:06 +01:00
|
|
|
d = tan(p1->u.d);
|
|
|
|
if (fabs(d) < 1e-10)
|
|
|
|
d = 0.0;
|
|
|
|
push_double(d);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expomode == 1) {
|
2004-06-25 22:45:15 +02:00
|
|
|
push(imaginaryunit);
|
2004-03-03 21:24:06 +01:00
|
|
|
push(p1);
|
|
|
|
multiply();
|
|
|
|
exponential();
|
|
|
|
p2 = pop();
|
2004-06-25 22:45:15 +02:00
|
|
|
push(imaginaryunit);
|
2004-03-03 21:24:06 +01:00
|
|
|
push(p1);
|
|
|
|
multiply();
|
|
|
|
negate();
|
|
|
|
exponential();
|
|
|
|
p3 = pop();
|
|
|
|
push(p3);
|
|
|
|
push(p2);
|
|
|
|
subtract();
|
2004-06-25 22:45:15 +02:00
|
|
|
push(imaginaryunit);
|
2004-03-03 21:24:06 +01:00
|
|
|
multiply();
|
|
|
|
push(p2);
|
|
|
|
push(p3);
|
|
|
|
add();
|
|
|
|
divide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// multiply by 180/pi
|
|
|
|
|
|
|
|
push(p1);
|
|
|
|
push_integer(180);
|
|
|
|
multiply();
|
|
|
|
push_symbol(PI);
|
|
|
|
divide();
|
|
|
|
|
|
|
|
n = pop_integer();
|
|
|
|
|
|
|
|
if (n == (int) 0x80000000) {
|
|
|
|
push_symbol(TAN);
|
|
|
|
push(p1);
|
|
|
|
list(2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(n % 360) {
|
|
|
|
case -315:
|
|
|
|
push_integer(1);
|
|
|
|
break;
|
|
|
|
case -225:
|
|
|
|
push_integer(-1);
|
|
|
|
break;
|
|
|
|
case -180:
|
|
|
|
push_integer(0);
|
|
|
|
break;
|
|
|
|
case -135:
|
|
|
|
push_integer(1);
|
|
|
|
break;
|
|
|
|
case -45:
|
|
|
|
push_integer(-1);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
push_integer(0);
|
|
|
|
break;
|
|
|
|
case 45:
|
|
|
|
push_integer(1);
|
|
|
|
break;
|
|
|
|
case 135:
|
|
|
|
push_integer(-1);
|
|
|
|
break;
|
|
|
|
case 180:
|
|
|
|
push_integer(0);
|
|
|
|
break;
|
|
|
|
case 225:
|
|
|
|
push_integer(1);
|
|
|
|
break;
|
|
|
|
case 315:
|
|
|
|
push_integer(-1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
push_symbol(TAN);
|
|
|
|
push(p1);
|
|
|
|
list(2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
"tan(x)",
|
|
|
|
"tan(x)",
|
|
|
|
|
|
|
|
"tan(-2 pi)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(-7 pi/4)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"tan(-5 pi/4)",
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
"tan(-pi)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(-3 pi/4)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"tan(-pi/4)",
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
"tan(0)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(pi/4)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"tan(3 pi/4)",
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
"tan(pi)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(5 pi/4)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"tan(7 pi/4)",
|
|
|
|
"-1",
|
|
|
|
|
|
|
|
"tan(2 pi)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(-2 pi)+tan(float(-2 pi))",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(-7 pi/4)+tan(float(-7 pi/4))",
|
|
|
|
"2",
|
|
|
|
|
|
|
|
"tan(-5 pi/4)+tan(float(-5 pi/4))",
|
|
|
|
"-2",
|
|
|
|
|
|
|
|
"tan(-pi)+tan(float(-pi))",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(-3 pi/4)+tan(float(-3 pi/4))",
|
|
|
|
"2",
|
|
|
|
|
|
|
|
"tan(-pi/4)+tan(float(-pi/4))",
|
|
|
|
"-2",
|
|
|
|
|
|
|
|
"tan(0)+tan(0.0)",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(pi/4)+tan(float(pi/4))",
|
|
|
|
"2",
|
|
|
|
|
|
|
|
"tan(3 pi/4)+tan(float(3 pi/4))",
|
|
|
|
"-2",
|
|
|
|
|
|
|
|
"tan(pi)+tan(float(pi))",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"tan(5 pi/4)+tan(float(5 pi/4))",
|
|
|
|
"2",
|
|
|
|
|
|
|
|
"tan(7 pi/4)+tan(float(7 pi/4))",
|
|
|
|
"-2",
|
|
|
|
|
|
|
|
"tan(2 pi)+tan(float(2 pi))",
|
|
|
|
"0",
|
|
|
|
|
|
|
|
"expomode=1",
|
|
|
|
"",
|
|
|
|
|
|
|
|
"tan(x)",
|
|
|
|
"i*exp(-i*x)/(exp(-i*x)+exp(i*x))-i*exp(i*x)/(exp(-i*x)+exp(i*x))",
|
|
|
|
|
|
|
|
"expomode=0",
|
|
|
|
"",
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_tan(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|