fix historical trigonometric functions for values of 0

Fixed how the historical trigonometric functions call
the underlying trigonometric functions.  This fixes a
number of issues where the function for values of 0.

Updated cal/regress.cal to test historical trigonometric functions
at the  0 value.
This commit is contained in:
Landon Curt Noll
2023-09-06 18:02:46 -07:00
parent c153ac08b9
commit b67e20881a
2 changed files with 32 additions and 58 deletions

View File

@@ -3509,6 +3509,8 @@ define test_trig()
pi = pi(1e-20);
/* test versed trigonometric sine */
vrfy(versin(0, 1e-10) == 0,
strcat(str(tnum++), ': versin(0, 1e-10) == 0'));
vrfy(round(versin(0.2, 1e-10), 10) == 0.0199334222,
strcat(str(tnum++),
': round(versin(0.2, 1e-10), 10) == 0.0199334222'));
@@ -3534,11 +3536,11 @@ define test_trig()
': round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i'));
/* test inverse versed trigonometric sine */
vrfy(aversin(0) == 0,
strcat(str(tnum++), ': aversin(0) == 0'));
vrfy(round(aversin(0.5, 1e-10), 10) == 1.0471975512,
strcat(str(tnum++),
': round(aversin(0.5, 1e-10), 10) == 1.0471975512'));
vrfy(aversin(0) == 0,
strcat(str(tnum++), ': aversin(0) == 0'));
vrfy(round(aversin(-5, 1e-10), 10) == 2.4778887303i,
strcat(str(tnum++),
': round(aversin(-5, 1e-10), 10) == 2.4778887303i'));
@@ -3547,6 +3549,8 @@ define test_trig()
': round(aversin(2 + 3i, 1e-10), 10) == 1.8783999763+1.8641615439i'));
/* test coversed trigonometric sine */
vrfy(coversin(0, 1e-10) == 1,
strcat(str(tnum++), ': coversin(0, 1e-10) == 1'));
vrfy(round(coversin(0.2, 1e-10), 10) == 0.8013306692,
strcat(str(tnum++),
': round(coversin(0.2, 1e-10), 10) == 0.8013306692'));
@@ -3572,6 +3576,9 @@ define test_trig()
': round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i'));
/* test inverse coversed trigonometric sine */
vrfy(round(acoversin(0, 1e-10), 10) == 1.5707963268,
strcat(str(tnum++),
': round(acoversin(0.5, 1e-10), 10) == 1.5707963268'));
vrfy(round(acoversin(0.5, 1e-10), 10) == 0.5235987756,
strcat(str(tnum++),
': round(acoversin(0.5, 1e-10), 10) == 0.5235987756'));
@@ -3585,6 +3592,8 @@ define test_trig()
': round(acoversin(2 + 3i, 1e-10), 10) == -0.3076036495-1.8641615442i'));
/* test versed trigonometric cosine */
vrfy(vercos(0, 1e-10) == 2,
strcat(str(tnum++), ': vercos(0, 1e-10) == 2'));
vrfy(round(vercos(0.2, 1e-10), 10) == 1.9800665778,
strcat(str(tnum++),
': round(vercos(0.2, 1e-10), 10) == 1.9800665778'));
@@ -3610,6 +3619,9 @@ define test_trig()
': round(vercos(2 + 3i, 1e-10), 10) == -3.189625691-9.1092278938i'));
/* test inverse versed trigonometric cosine */
vrfy(round(avercos(0, 1e-10), 10) == 3.1415926536,
strcat(str(tnum++),
': round(avercos(0, 1e-10), 10) == 3.1415926536'));
vrfy(round(avercos(0.5, 1e-10), 10) == 2.0943951024,
strcat(str(tnum++),
': round(avercos(0.5, 1e-10), 10) == 2.0943951024'));
@@ -3623,6 +3635,8 @@ define test_trig()
': round(avercos(2 + 3i, 1e-10), 10) == 1.2631926773-1.8641615442i'));
/* test coversed trigonometric cosine */
vrfy(covercos(0, 1e-10) == 1,
strcat(str(tnum++), ': covercos(0, 1e-10) == 1'));
vrfy(round(covercos(0.2, 1e-10), 10) == 1.1986693308,
strcat(str(tnum++),
': round(covercos(0.2, 1e-10), 10) == 1.1986693308'));
@@ -3648,6 +3662,9 @@ define test_trig()
': round(covercos(2 + 3i, 1e-10), 10) == 10.1544991469-4.16890696i'));
/* test inverse coversed trigonometric cosine */
vrfy(round(acovercos(0, 1e-10), 10) == 1.5707963268,
strcat(str(tnum++),
': round(acovercos(0, 1e-10), 10) == 1.5707963268'));
vrfy(round(acovercos(0.5, 1e-10), 10) == 0.5235987756,
strcat(str(tnum++),
': round(acovercos(0.5, 1e-10), 10) == 0.5235987756'));

View File

@@ -1995,9 +1995,8 @@ qacoth(NUMBER *q, NUMBER *epsilon)
NUMBER *
qversin(NUMBER *q, NUMBER *epsilon)
{
NUMBER *sin, *cos, *res;
NUMBER *versin;
long n;
NUMBER *res;
NUMBER *cos;
/*
* firewall
@@ -2014,18 +2013,10 @@ qversin(NUMBER *q, NUMBER *epsilon)
/*
* calculate trig function value
*/
n = -qilog2(epsilon);
qsincos(q, n + 2, &sin, &cos);
qfree(sin);
versin = qsub(&_qone_, cos);
cos = qcos(q, epsilon);
res = qsub(&_qone_, cos);
qfree(cos);
/*
* round value to nearest epsilon
*/
res = qmappr(versin, epsilon, 24);
qfree(versin);
/*
* return 1 - cos(x)
*/
@@ -2151,9 +2142,7 @@ qaversin(NUMBER *q, NUMBER *epsilon)
NUMBER *
qcoversin(NUMBER *q, NUMBER *epsilon)
{
NUMBER *sin, *cos, *res;
NUMBER *coversin;
long n;
NUMBER *sin, *res;
/*
* firewall
@@ -2170,20 +2159,10 @@ qcoversin(NUMBER *q, NUMBER *epsilon)
/*
* calculate trig function value
*/
n = -qilog2(epsilon);
if (qiszero(q) || n < 0)
return qlink(&_qzero_);
qsincos(q, n + 2, &sin, &cos);
qfree(cos);
coversin = qsub(&_qone_, sin);
sin = qsin(q, epsilon);
res = qsub(&_qone_, sin);
qfree(sin);
/*
* round value to nearest epsilon
*/
res = qmappr(coversin, epsilon, 24);
qfree(coversin);
/*
* return 1 - sin(x)
*/
@@ -2312,9 +2291,7 @@ qacoversin(NUMBER *q, NUMBER *epsilon)
NUMBER *
qvercos(NUMBER *q, NUMBER *epsilon)
{
NUMBER *sin, *cos, *res;
NUMBER *vercos;
long n;
NUMBER *cos, *res;
/*
* firewall
@@ -2331,18 +2308,10 @@ qvercos(NUMBER *q, NUMBER *epsilon)
/*
* calculate trig function value
*/
n = -qilog2(epsilon);
qsincos(q, n + 2, &sin, &cos);
qfree(sin);
vercos = qqadd(&_qone_, cos);
cos = qcos(q, epsilon);
res = qqadd(&_qone_, cos);
qfree(cos);
/*
* round value to nearest epsilon
*/
res = qmappr(vercos, epsilon, 24);
qfree(vercos);
/*
* return 1 + cos(x)
*/
@@ -2468,9 +2437,7 @@ qavercos(NUMBER *q, NUMBER *epsilon)
NUMBER *
qcovercos(NUMBER *q, NUMBER *epsilon)
{
NUMBER *sin, *cos, *res;
NUMBER *covercos;
long n;
NUMBER *sin, *res;
/*
* firewall
@@ -2487,20 +2454,10 @@ qcovercos(NUMBER *q, NUMBER *epsilon)
/*
* calculate trig function value
*/
n = -qilog2(epsilon);
if (qiszero(q) || n < 0)
return qlink(&_qzero_);
qsincos(q, n + 2, &sin, &cos);
qfree(cos);
covercos = qqadd(&_qone_, sin);
sin = qsin(q, epsilon);
res = qqadd(&_qone_, sin);
qfree(sin);
/*
* round value to nearest epsilon
*/
res = qmappr(covercos, epsilon, 24);
qfree(covercos);
/*
* return 1 + sin(x)
*/