代码拉取完成,页面将自动刷新
#include "stdafx.h"
#include "defs.h"
void
eval_arcsin(void)
{
push(cadr(p1));
eval();
arcsin();
}
void
arcsin(void)
{
int n;
double d;
save();
p1 = pop();
if (car(p1) == symbol(SIN)) {
push(cadr(p1));
restore();
return;
}
if (isdouble(p1)) {
errno = 0;
d = asin(p1->u.d);
if (errno)
stop("arcsin function argument is not in the interval [-1,1]");
push_double(d);
restore();
return;
}
// if p1 == 1/sqrt(2) then return 1/4*pi (45 degrees)
if (isoneoversqrttwo(p1)) {
push_rational(1, 4);
push_symbol(PI);
multiply();
restore();
return;
}
// if p1 == -1/sqrt(2) then return -1/4*pi (-45 degrees)
if (isminusoneoversqrttwo(p1)) {
push_rational(-1, 4);
push_symbol(PI);
multiply();
restore();
return;
}
if (!isrational(p1)) {
push_symbol(ARCSIN);
push(p1);
list(2);
restore();
return;
}
push(p1);
push_integer(2);
multiply();
n = pop_integer();
switch (n) {
case -2:
push_rational(-1, 2);
push_symbol(PI);
multiply();
break;
case -1:
push_rational(-1, 6);
push_symbol(PI);
multiply();
break;
case 0:
push(zero);
break;
case 1:
push_rational(1, 6);
push_symbol(PI);
multiply();
break;
case 2:
push_rational(1, 2);
push_symbol(PI);
multiply();
break;
default:
push_symbol(ARCSIN);
push(p1);
list(2);
break;
}
restore();
}
#if SELFTEST
static const char *s[] = {
"arcsin(-1)",
"-1/2*pi",
"arcsin(-1/2)",
"-1/6*pi",
"arcsin(0)",
"0",
"arcsin(1/2)",
"1/6*pi",
"arcsin(1)",
"1/2*pi",
"arcsin(sin(-1/2*pi))",
"-1/2*pi",
"arcsin(sin(-1/6*pi))",
"-1/6*pi",
"arcsin(sin(0))",
"0",
"arcsin(sin(1/6*pi))",
"1/6*pi",
"arcsin(sin(1/2*pi))",
"1/2*pi",
"arcsin(sin(x))",
"x",
"arcsin(1/sqrt(2))",
"1/4*pi",
"arcsin(-1/sqrt(2))",
"-1/4*pi",
"arcsin(sin(1/4*pi))",
"1/4*pi",
"arcsin(sin(-1/4*pi))",
"-1/4*pi",
};
void
test_arcsin(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。