mirror of
https://github.com/lcn2/calc.git
synced 2025-08-16 01:03:29 +03:00
add new versin and vercos builtin functions
Added new versin(x, [,eps]) for versed sine and vercos(x, [,eps]) for versed cosine. Updated trig help files.
This commit is contained in:
59
qtrans.c
59
qtrans.c
@@ -229,7 +229,6 @@ qcos(NUMBER *q, NUMBER *epsilon)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This calls qsincos() and discards the value of cos.
|
||||
*/
|
||||
@@ -1973,3 +1972,61 @@ qacoth(NUMBER *q, NUMBER *epsilon)
|
||||
qfree(tmp);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* versed sine - this calls qsincos() and discards the value of sin.
|
||||
*
|
||||
* This uses the formula: versin(x) = 1 - cos(x).
|
||||
*/
|
||||
NUMBER *
|
||||
qversin(NUMBER *q, NUMBER *epsilon)
|
||||
{
|
||||
NUMBER *sin, *cos, *res;
|
||||
NUMBER *versin;
|
||||
long n;
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for %s", __func__);
|
||||
not_reached();
|
||||
}
|
||||
n = -qilog2(epsilon);
|
||||
if (qiszero(q) || n < 0)
|
||||
return qlink(&_qzero_);
|
||||
qsincos(q, n + 2, &sin, &cos);
|
||||
qfree(sin);
|
||||
versin = qsub(&_qone_, cos);
|
||||
qfree(cos);
|
||||
res = qmappr(versin, epsilon, 24);
|
||||
qfree(versin);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* versed cosine - this calls qsincos() and discards the value of cos.
|
||||
*
|
||||
* This uses the formula: vercos(x) = 1 - sin(x).
|
||||
*/
|
||||
NUMBER *
|
||||
qvercos(NUMBER *q, NUMBER *epsilon)
|
||||
{
|
||||
NUMBER *sin, *cos, *res;
|
||||
NUMBER *vercos;
|
||||
long n;
|
||||
|
||||
if (qiszero(epsilon)) {
|
||||
math_error("Zero epsilon value for %s", __func__);
|
||||
not_reached();
|
||||
}
|
||||
n = -qilog2(epsilon);
|
||||
if (qiszero(q) || n < 0)
|
||||
return qlink(&_qzero_);
|
||||
qsincos(q, n + 2, &sin, &cos);
|
||||
qfree(cos);
|
||||
vercos = qsub(&_qone_, sin);
|
||||
qfree(sin);
|
||||
res = qmappr(vercos, epsilon, 24);
|
||||
qfree(vercos);
|
||||
return res;
|
||||
}
|
||||
|
Reference in New Issue
Block a user