add trigonometric chord of a unit circle functions

Improve builtin function strings, as printed by help builtin,
that use an optional accuracy (epsilon) arg by adding a comma.

Added the following new trigonometric functions:

    crd(x [,eps])		trigonometric chord of a unit circle
    acrd(x [,eps])		inverse trigonometric chord of a unit circle
This commit is contained in:
Landon Curt Noll
2023-10-02 22:43:33 -07:00
parent c78a893862
commit 26fc394089
44 changed files with 1246 additions and 118 deletions

View File

@@ -364,6 +364,16 @@ define compare(ident_val, trig_val, name, index, testnum)
{
local abs_diff; /* absolute difference between ident_val and trig_val */
/*
* firewall
*/
if (!isnum(trig_val)) {
printf("**** trig test %d-%d failed: %s(tval[%d]): ",
testnum, index, name, index);
printf("%d returned a non-numeric value\n", trig_val);
return 1;
}
/*
* compute absolute difference
*/
@@ -1244,3 +1254,61 @@ define verify_excsc(testnum)
}
return error_count;
}
/*
* verify_crd - verify trigonometric chord of a unit circle
*
* We use the following trigonometric identity:
*
* crd(x) = 2 * sin(x / 2)
*
* given:
* testnum regression test number being performed
*
* returns:
* number of tests that failed
*/
define verify_crd(testnum)
{
local tval_len; /* current length of the tval[] array */
local ident_val; /* computed trig value trigonometric identity */
local trig_val; /* computed value from the trigonometric function */
local error_count; /* number of compare errors detected */
local i;
/*
* firewall
*/
if (size(sin_tval) <= 0) {
precompute_trig();
}
/*
* for each test value, verify the trigonometric identity within epsilon
*/
tval_len = size(tval);
for (i=0; i < tval_len; ++i) {
/* NOTE: We actually check the identity: crd(x*2) = 2 * sin(x) */
/* compute trigonometric identity */
ident_val = 2 * sin_tval[i];
/* compute trigonometric function */
trig_val = crd(tval[i] * 2);
/* compare trigonometric identity with trigonometric function value */
if (compare(ident_val, trig_val, "crd", i, testnum)) {
++error_count;
}
}
/*
* report test results
*/
if (error_count != 0) {
print '**** test', testnum : ': crd test failure count:', error_count;
}
return error_count;
}