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:
Landon Curt Noll
2023-09-01 17:38:14 -07:00
parent 1c839dfede
commit b0a48a2b70
18 changed files with 493 additions and 52 deletions

View File

@@ -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;
}