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

@@ -4138,6 +4138,50 @@ define test_trig()
strcat(str(tnum++),
': round(aexcsc(2 + 3i, 1e-10), 10) == 0.1650861985-0.1681700706i'));
/* test trigonometric chord of a unit circle */
vrfy(crd(0, 1e-10) == 0,
strcat(str(tnum++), ': crd(0, 1e-10) == 0'));
vrfy(round(crd(0.2, 1e-10), 10) == 0.1996668332,
strcat(str(tnum++),
': round(crd(0.2, 1e-10), 10) == 0.1996668332'));
vrfy(round(crd(3/7, 1e-10), 10) == 0.4252990674,
strcat(str(tnum++),
': round(crd(3/7, 1e-10), 10) == 0.4252990674'));
vrfy(round(crd(-31, 1e-10), 10) == -0.4129349638,
strcat(str(tnum++),
': round(crd(-31, 1e-10), 10) == -0.4129349638'));
vrfy(crd(pi/3, 1e-10) == 1,
strcat(str(tnum++), ': crd(pi/3, 1e-10) == 1'));
vrfy(crd(pi, 1e-10) == 2,
strcat(str(tnum++), ': crd(pi, 1e-10) == 2'));
vrfy(crd(5*pi/3, 1e-10) == 1,
strcat(str(tnum++), ': crd(5*pi/3, 1e-10) == 1'));
vrfy(round(crd(1, 1e-10), 10) == 0.9588510772,
strcat(str(tnum++),
': round(crd(1, 1e-10), 10) == 0.9588510772'));
vrfy(round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i,
strcat(str(tnum++),
': round(crd(2 + 3i, 1e-10), 10) == 3.9589688712+2.3009091988i'));
/* test inverse trigonometric chord of a unit circle */
vrfy(acrd(0, 1e-10) == 0,
strcat(str(tnum++), ': acrd(0, 1e-10) == 0'));
vrfy(round(acrd(0.2, 1e-10), 10) == 0.2003348424,
strcat(str(tnum++),
': round(acrd(0.2, 1e-10), 10) == 0.2003348424'));
vrfy(round(acrd(3/7, 1e-10), 10) == 0.4319209974,
strcat(str(tnum++),
': round(acrd(3/7, 1e-10), 10) == 0.4319209974'));
vrfy(round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i,
strcat(str(tnum++),
': round(acrd(-31, 1e-10), 10) == -3.1415926536+6.8658899902i'));
vrfy(round(acrd(1, 1e-10), 10) == 1.0471975512,
strcat(str(tnum++),
': round(acrd(1, 1e-10), 10) == 1.0471975512'));
vrfy(round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i,
strcat(str(tnum++),
': round(acrd(2 + 3i, 1e-10), 10) == 1.0471975512+2.6339157938i'));
print strcat(str(tnum++), ': Ending test_trig');
}
print '051: parsed test_trig()';
@@ -9835,8 +9879,9 @@ vrfy(verify_havercos(9513) == 0, '9513: verify_havercos(9513) == 0');
vrfy(verify_hacovercos(9514) == 0, '9514: verify_hacovercos(9514) == 0');
vrfy(verify_exsec(9515) == 0, '9515: verify_exsec(9515) == 0');
vrfy(verify_excsc(9516) == 0, '9516: verify_excsc(9516) == 0');
vrfy(verify_crd(9517) == 0, '9516: verify_excsc(9517) == 0');
print '9517: Ending trigonometric identities test set';
print '9518: Ending trigonometric identities test set';
/*
@@ -10839,6 +10884,12 @@ vrfy_errsym(10590, 10590, "E_EXCSC_4");
vrfy_errsym(10591, 10591, "E_AEXCSC_1");
vrfy_errsym(10592, 10592, "E_AEXCSC_2");
vrfy_errsym(10593, 10593, "E_AEXCSC_3");
vrfy_errsym(10594, 10594, "E_CRD_1");
vrfy_errsym(10595, 10595, "E_CRD_2");
vrfy_errsym(10596, 10596, "E_CRD_3");
vrfy_errsym(10597, 10597, "E_ACRD_1");
vrfy_errsym(10598, 10598, "E_ACRD_2");
vrfy_errsym(10599, 10599, "E_ACRD_3");
/* ************************************************************** */
/* NOTE: Reserve thru test 10998 for calc computation error codes */

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