rename vercos to coversin

The code to compute 1 - sin(x) belongs to coversin, not vercos.
This commit is contained in:
Landon Curt Noll
2023-09-01 23:26:26 -07:00
parent b0a48a2b70
commit 7398fbb2e9
17 changed files with 93 additions and 89 deletions

View File

@@ -99,7 +99,7 @@ The following are the changes from calc version 2.14.3.5 to date:
Document in help files for builtin functions that take eps arguments, Document in help files for builtin functions that take eps arguments,
the LIMIT range for such eps values. the LIMIT range for such eps values.
Added new versin(x, [,eps]) for versed sine and vercos(x, [,eps]) Added new versin(x, [,eps]) for versed sine and coversin(x, [,eps])
for versed cosine. for versed cosine.

View File

@@ -3533,31 +3533,31 @@ define test_trig()
strcat(str(tnum++), strcat(str(tnum++),
': round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i')); ': round(versin(2 + 3i, 1e-10), 10) == 5.189625691+9.1092278938i'));
/* test versed cosine */ /* test coversed sine */
pi = pi(1e-20); pi = pi(1e-20);
vrfy(round(vercos(0.2, 1e-10), 10) == 0.8013306692, vrfy(round(coversin(0.2, 1e-10), 10) == 0.8013306692,
strcat(str(tnum++), strcat(str(tnum++),
': round(vercos(0.2, 1e-10), 10) == 0.8013306692')); ': round(coversin(0.2, 1e-10), 10) == 0.8013306692'));
vrfy(round(vercos(3/7, 1e-10), 10) == 0.584428145, vrfy(round(coversin(3/7, 1e-10), 10) == 0.584428145,
strcat(str(tnum++), strcat(str(tnum++),
': round(vercos(3/7, 1e-10), 10) == 0.584428145')); ': round(coversin(3/7, 1e-10), 10) == 0.584428145'));
vrfy(round(vercos(-31, 1e-10), 10) == 0.5959623547, vrfy(round(coversin(-31, 1e-10), 10) == 0.5959623547,
strcat(str(tnum++), strcat(str(tnum++),
': round(vercos(-31, 1e-10), 10) == 0.5959623547')); ': round(coversin(-31, 1e-10), 10) == 0.5959623547'));
vrfy(vercos(pi/6, 1e-10) == 0.5, vrfy(coversin(pi/6, 1e-10) == 0.5,
strcat(str(tnum++), ': vercos(pi/6, 1e-10) == 0.5')); strcat(str(tnum++), ': coversin(pi/6, 1e-10) == 0.5'));
vrfy(vercos(pi/2, 1e-10) == 0, vrfy(coversin(pi/2, 1e-10) == 0,
strcat(str(tnum++), ': vercos(pi/2, 1e-10) == 0')); strcat(str(tnum++), ': coversin(pi/2, 1e-10) == 0'));
vrfy(vercos(pi, 1e-10) == 1, vrfy(coversin(pi, 1e-10) == 1,
strcat(str(tnum++), ': vercos(pi, 1e-10) == 1')); strcat(str(tnum++), ': coversin(pi, 1e-10) == 1'));
vrfy(vercos(3*pi/2, 1e-10) == 2, vrfy(coversin(3*pi/2, 1e-10) == 2,
strcat(str(tnum++), ': vercos(3*pi/2, 1e-10) == 2')); strcat(str(tnum++), ': coversin(3*pi/2, 1e-10) == 2'));
vrfy(round(vercos(1, 1e-10), 10) == 0.1585290152, vrfy(round(coversin(1, 1e-10), 10) == 0.1585290152,
strcat(str(tnum++), strcat(str(tnum++),
': round(vercos(1, 1e-10), 10) == 0.1585290152')); ': round(coversin(1, 1e-10), 10) == 0.1585290152'));
vrfy(round(vercos(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i, vrfy(round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i,
strcat(str(tnum++), strcat(str(tnum++),
': round(vercos(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i')); ': round(coversin(2 + 3i, 1e-10), 10) == -8.1544991469+4.16890696i'));
print strcat(str(tnum++), ': Ending test_trig'); print strcat(str(tnum++), ': Ending test_trig');
} }

View File

@@ -553,6 +553,6 @@ E_LOGN_5 Non-numeric second argument for logn
E_VERSIN1 Bad epsilon for versin E_VERSIN1 Bad epsilon for versin
E_VERSIN2 Bad first argument for versin E_VERSIN2 Bad first argument for versin
E_VERSIN3 Too-large im(argument) for versin E_VERSIN3 Too-large im(argument) for versin
E_VERCOS1 Bad epsilon for vercos E_COVERSIN1 Bad epsilon for coversin
E_VERCOS2 Bad first argument for vercos E_COVERSIN2 Bad first argument for coversin
E_VERCOS3 Too-large im(argument) for vercos E_COVERSIN3 Too-large im(argument) for coversin

View File

@@ -119,7 +119,7 @@ E_FUNC COMPLEX *c_acsch(COMPLEX *c, NUMBER *epsilon);
E_FUNC COMPLEX *c_gd(COMPLEX *c, NUMBER *epsilon); E_FUNC COMPLEX *c_gd(COMPLEX *c, NUMBER *epsilon);
E_FUNC COMPLEX *c_agd(COMPLEX *c, NUMBER *epsilon); E_FUNC COMPLEX *c_agd(COMPLEX *c, NUMBER *epsilon);
E_FUNC COMPLEX *c_versin(COMPLEX *c, NUMBER *epsilon); E_FUNC COMPLEX *c_versin(COMPLEX *c, NUMBER *epsilon);
E_FUNC COMPLEX *c_vercos(COMPLEX *c, NUMBER *epsilon); E_FUNC COMPLEX *c_coversin(COMPLEX *c, NUMBER *epsilon);

View File

@@ -1371,10 +1371,10 @@ c_versin(COMPLEX *c, NUMBER *epsilon)
* *
* This uses the formula: * This uses the formula:
* *
* vercos(x) = 1 - sin(x) * coversin(x) = 1 - sin(x)
*/ */
COMPLEX * COMPLEX *
c_vercos(COMPLEX *c, NUMBER *epsilon) c_coversin(COMPLEX *c, NUMBER *epsilon)
{ {
COMPLEX *r; /* return COMPLEX value */ COMPLEX *r; /* return COMPLEX value */
COMPLEX *ctmp; /* complex sin(c) */ COMPLEX *ctmp; /* complex sin(c) */
@@ -1387,7 +1387,7 @@ c_vercos(COMPLEX *c, NUMBER *epsilon)
not_reached(); not_reached();
} }
if (check_epsilon(epsilon) == false) { if (check_epsilon(epsilon) == false) {
math_error("Invalid epsilon value for complex vercos"); math_error("Invalid epsilon value for complex coversin");
not_reached(); not_reached();
} }
@@ -1396,7 +1396,7 @@ c_vercos(COMPLEX *c, NUMBER *epsilon)
*/ */
ctmp = c_sin(c, epsilon); ctmp = c_sin(c, epsilon);
if (ctmp == NULL) { if (ctmp == NULL) {
math_error("Failed to compute complex sin for complex vercos"); math_error("Failed to compute complex sin for complex coversin");
not_reached(); not_reached();
} }
r = c_sub(&_cone_, ctmp); r = c_sub(&_cone_, ctmp);

16
func.c
View File

@@ -3538,7 +3538,7 @@ f_versin(int count, VALUE **vals)
S_FUNC VALUE S_FUNC VALUE
f_vercos(int count, VALUE **vals) f_coversin(int count, VALUE **vals)
{ {
VALUE result; VALUE result;
COMPLEX *c; COMPLEX *c;
@@ -3555,7 +3555,7 @@ f_vercos(int count, VALUE **vals)
eps = conf->epsilon; eps = conf->epsilon;
if (count == 2) { if (count == 2) {
if (verify_eps(vals[1]) == false) { if (verify_eps(vals[1]) == false) {
return error_value(E_VERCOS1); return error_value(E_COVERSIN1);
} }
eps = vals[1]->v_num; eps = vals[1]->v_num;
} }
@@ -3565,13 +3565,13 @@ f_vercos(int count, VALUE **vals)
*/ */
switch (vals[0]->v_type) { switch (vals[0]->v_type) {
case V_NUM: case V_NUM:
result.v_num = qvercos(vals[0]->v_num, eps); result.v_num = qcoversin(vals[0]->v_num, eps);
result.v_type = V_NUM; result.v_type = V_NUM;
break; break;
case V_COM: case V_COM:
c = c_vercos(vals[0]->v_com, eps); c = c_coversin(vals[0]->v_com, eps);
if (c == NULL) { if (c == NULL) {
return error_value(E_VERCOS3); return error_value(E_COVERSIN3);
} }
result.v_com = c; result.v_com = c;
result.v_type = V_COM; result.v_type = V_COM;
@@ -3582,7 +3582,7 @@ f_vercos(int count, VALUE **vals)
} }
break; break;
default: default:
return error_value(E_VERCOS2); return error_value(E_COVERSIN2);
} }
return result; return result;
} }
@@ -10859,6 +10859,8 @@ STATIC CONST struct builtin builtins[] = {
"hyperbolic cotangent of a within accuracy b"}, "hyperbolic cotangent of a within accuracy b"},
{"count", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_count}, {"count", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_count},
"count listr/matrix elements satisfying some condition"}, "count listr/matrix elements satisfying some condition"},
{"coversin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_coversin},
"coversed sine of value a within accuracy b"},
{"cp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_cp}, {"cp", 2, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_2 = f_cp},
"cross product of two vectors"}, "cross product of two vectors"},
{"csc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csc}, {"csc", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_csc},
@@ -11416,8 +11418,6 @@ STATIC CONST struct builtin builtins[] = {
"unget char read from file"}, "unget char read from file"},
{"usertime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_usertime}, {.null = NULL}, {"usertime", 0, 0, 0, OP_NOP, {.numfunc_0 = f_usertime}, {.null = NULL},
"user mode CPU time in seconds"}, "user mode CPU time in seconds"},
{"vercos", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_vercos},
"versed cosine of value a within accuracy b"},
{"versin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_versin}, {"versin", 1, 2, 0, OP_NOP, {.null = NULL}, {.valfunc_cnt = f_versin},
"versed sine of value a within accuracy b"}, "versed sine of value a within accuracy b"},
{"version", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_version}, {"version", 0, 0, 0, OP_NOP, {.null = NULL}, {.valfunc_0 = f_version},

View File

@@ -203,33 +203,33 @@ DETAIL_HELP= abs access acos acosh acot acoth acsc acsch address agd \
append appr arg argv arrow asec asech asin asinh assign atan atan2 \ append appr arg argv arrow asec asech asin asinh assign atan atan2 \
atanh avg base base2 bernoulli bit blk blkcpy blkfree blocks bround \ atanh avg base base2 bernoulli bit blk blkcpy blkfree blocks bround \
btrunc calc_tty calclevel calcpath catalan ceil cfappr cfsim char \ btrunc calc_tty calclevel calcpath catalan ceil cfappr cfsim char \
cmdbuf cmp comb conj cos cosh cot coth count cp csc csch ctime d2dm \ cmdbuf cmp comb conj cos cosh cot coth count coversin cp csc csch \
d2dms d2g d2r delete den dereference det digit digits display dms2d dp \ ctime d2dm d2dms d2g d2r delete den dereference det digit digits \
epsilon errcount errmax errno error estr euler eval exp fact factor \ display dms2d dp epsilon errcount errmax errno error estr euler eval \
fclose fcnt feof ferror fflush fgetc fgetfield fgetfile fgetline fgets \ exp fact factor fclose fcnt feof ferror fflush fgetc fgetfield \
fgetstr fib files floor fopen forall fpathopen fprintf fputc fputs \ fgetfile fgetline fgets fgetstr fib files floor fopen forall fpathopen \
fputstr frac free freebernoulli freeeuler freeglobals freeredc \ fprintf fputc fputs fputstr frac free freebernoulli freeeuler \
freestatics frem freopen fscan fscanf fseek fsize ftell g2d g2gm g2gms \ freeglobals freeredc freestatics frem freopen fscan fscanf fseek fsize \
g2r gcd gcdrem gd getenv gms2g h2hm h2hms hash head highbit hmean \ ftell g2d g2gm g2gms g2r gcd gcdrem gd getenv gms2g h2hm h2hms hash \
hms2h hnrmod hypot ilog ilog10 ilog2 im indices inputlevel insert int \ head highbit hmean hms2h hnrmod hypot ilog ilog10 ilog2 im indices \
inverse iroot isalnum isalpha isassoc isatty isblk iscntrl isconfig \ inputlevel insert int inverse iroot isalnum isalpha isassoc isatty \
isdefined isdigit iserror iseven isfile isgraph ishash isident isint \ isblk iscntrl isconfig isdefined isdigit iserror iseven isfile isgraph \
islist islower ismat ismult isnull isnum isobj isobjtype isodd isprime \ ishash isident isint islist islower ismat ismult isnull isnum isobj \
isprint isptr ispunct isqrt isrand israndom isreal isrel issimple \ isobjtype isodd isprime isprint isptr ispunct isqrt isrand israndom \
isspace issq isstr istype isupper isxdigit jacobi join lcm lcmfact \ isreal isrel issimple isspace issq isstr istype isupper isxdigit \
lfactor ln log log2 logn lowbit ltol makelist matdim matfill matmax \ jacobi join lcm lcmfact lfactor ln log log2 logn lowbit ltol makelist \
matmin matsum mattrace mattrans max memsize meq min minv mmin mne mod \ matdim matfill matmax matmin matsum mattrace mattrans max memsize meq \
modify name near newerror nextcand nextprime norm null num oldvalue \ min minv mmin mne mod modify name near newerror nextcand nextprime \
ord param perm pfact pi pix places pmod polar poly pop popcnt pound \ norm null num oldvalue ord param perm pfact pi pix places pmod polar \
power prevcand prevprime printf prompt protect ptest push putenv quo \ poly pop popcnt pound power prevcand prevprime printf prompt protect \
quomod r2d r2g rand randbit random randombit randperm rcin rcmul rcout \ ptest push putenv quo quomod r2d r2g rand randbit random randombit \
rcpow rcsq re remove reverse rewind rm root round rsearch runtime \ randperm rcin rcmul rcout rcpow rcsq re remove reverse rewind rm root \
saveval scale scan scanf search sec sech seed segment select sgn sha1 \ round rsearch runtime saveval scale scan scanf search sec sech seed \
sin sinh size sizeof sleep sort sqrt srand srandom ssq stoponerror str \ segment select sgn sha1 sin sinh size sizeof sleep sort sqrt srand \
strcasecmp strcat strcmp strcpy strerror strlen strncasecmp strncmp \ srandom ssq stoponerror str strcasecmp strcat strcmp strcpy strerror \
strncpy strpos strprintf strscan strscanf strtolower strtoupper substr \ strlen strncasecmp strncmp strncpy strpos strprintf strscan strscanf \
sum swap system systime tail tan tanh test time trunc usertime vercos \ strtolower strtoupper substr sum swap system systime tail tan tanh \
versin version xor test time trunc usertime versin version xor
# This list is of files that are clones of DETAIL_HELP files. They are # This list is of files that are clones of DETAIL_HELP files. They are
# built from DETAIL_HELP files. # built from DETAIL_HELP files.

View File

@@ -34,7 +34,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, tan, sec, csc, cot, epsilon sin, tan, sec, csc, cot, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2021,2023 Landon Curt Noll ## Copyright (C) 1999,2021,2023 Landon Curt Noll
## ##

View File

@@ -27,7 +27,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, cos, tan, sec, csc, epsilon sin, cos, tan, sec, csc, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2021,2023 Landon Curt Noll ## Copyright (C) 1999,2021,2023 Landon Curt Noll
## ##

View File

@@ -1,8 +1,8 @@
NAME NAME
vercos - versed cosine coversin - coversed sine
SYNOPSIS SYNOPSIS
vercos(x [,eps]) coversin(x [,eps])
TYPES TYPES
x number (real or complex) x number (real or complex)
@@ -14,31 +14,31 @@ DESCRIPTION
Calculate the versed cosine of x to a multiple of eps with error less in Calculate the versed cosine of x to a multiple of eps with error less in
absolute value than .75 * eps. absolute value than .75 * eps.
The versed cosine function is sometimes called coversin, sometimes called cvs, The coversed sine function is sometimes called covers, or cosiv, or cvs,
may be defined as: may be defined as:
vercos(x) = 1 - sin(x) coversin(x) = 1 - sin(x)
EXAMPLE EXAMPLE
; print vercos(0.2), vercos(3/7), vercos(-31) ; print coversin(0.2), coversin(3/7), coversin(-31)
0.80133066920493878454 0.58442814500694799193 0.59596235467693499395 0.80133066920493878454 0.58442814500694799193 0.59596235467693499395
; print vercos(1, 1e-5), vercos(1, 1e-10), vercos(1, 1e-15), vercos(1, 1e-20) ; print coversin(1, 1e-5), coversin(1, 1e-10), coversin(1, 1e-15), coversin(1, 1e-20)
0.15853 0.1585290152 0.158529015192104 0.15852901519210349335 0.15853 0.1585290152 0.158529015192104 0.15852901519210349335
; print vercos(2 + 3i, 1e-5), vercos(2 + 3i, 1e-10) ; print coversin(2 + 3i, 1e-5), coversin(2 + 3i, 1e-10)
-8.1545+4.16891i -8.1544991469+4.16890696i -8.1545+4.16891i -8.1544991469+4.16890696i
; pi = pi(1e-20) ; pi = pi(1e-20)
; print vercos(pi/6, 1e-10), vercos(pi/2, 1e-10), vercos(pi, 1e-10), vercos(3*pi/2, 1e-10) ; print coversin(pi/6, 1e-10), coversin(pi/2, 1e-10), coversin(pi, 1e-10), coversin(3*pi/2, 1e-10)
0.5 0 1 2 0.5 0 1 2
LIMITS LIMITS
0 < eps < 1 0 < eps < 1
LINK LIBRARY LINK LIBRARY
NUMBER *qvercos(NUMBER *x, NUMBER *eps) NUMBER *qcoversin(NUMBER *x, NUMBER *eps)
COMPLEX *c_vercos(COMPLEX *x, NUMBER *eps) COMPLEX *c_coversin(COMPLEX *x, NUMBER *eps)
SEE ALSO SEE ALSO
sin, cos, tan, sec, csc, cot, epsilon sin, cos, tan, sec, csc, cot, epsilon

View File

@@ -26,7 +26,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, cos, tan, sec, cot, epsilon sin, cos, tan, sec, cot, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2023 Landon Curt Noll ## Copyright (C) 1999,2023 Landon Curt Noll
## ##

View File

@@ -27,7 +27,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, cos, tan, csc, cot, epsilon sin, cos, tan, csc, cot, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2023 Landon Curt Noll ## Copyright (C) 1999,2023 Landon Curt Noll
## ##

View File

@@ -34,7 +34,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
cos, tan, sec, csc, cot, epsilon cos, tan, sec, csc, cot, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2021,2023 Landon Curt Noll ## Copyright (C) 1999,2021,2023 Landon Curt Noll
## ##

View File

@@ -28,7 +28,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, cos, sec, csc, cot, epsilon sin, cos, sec, csc, cot, epsilon
versin, vercos versin, coversin
## Copyright (C) 1999,2023 Landon Curt Noll ## Copyright (C) 1999,2023 Landon Curt Noll
## ##

View File

@@ -17,7 +17,7 @@ DESCRIPTION
The versed sine function is sometimes called vers, sometimes called ver, The versed sine function is sometimes called vers, sometimes called ver,
may be defined as: may be defined as:
versin(x) = 1 - cos(x) versin(x) = 1 - cos(x)
EXAMPLE EXAMPLE
; print versin(0.2), versin(3/7), versin(-31) ; print versin(0.2), versin(3/7), versin(-31)
@@ -42,7 +42,7 @@ LINK LIBRARY
SEE ALSO SEE ALSO
sin, cos, tan, sec, csc, cot, epsilon sin, cos, tan, sec, csc, cot, epsilon
vercos coversin
## Copyright (C) 2023 Landon Curt Noll ## Copyright (C) 2023 Landon Curt Noll
## ##

View File

@@ -223,7 +223,7 @@ E_FUNC void qfreebern(void);
E_FUNC NUMBER *qeuler(ZVALUE z); E_FUNC NUMBER *qeuler(ZVALUE z);
E_FUNC void qfreeeuler(void); E_FUNC void qfreeeuler(void);
E_FUNC NUMBER *qversin(NUMBER *q, NUMBER *epsilon); E_FUNC NUMBER *qversin(NUMBER *q, NUMBER *epsilon);
E_FUNC NUMBER *qvercos(NUMBER *q, NUMBER *epsilon); E_FUNC NUMBER *qcoversin(NUMBER *q, NUMBER *epsilon);
/* /*

View File

@@ -1977,7 +1977,9 @@ qacoth(NUMBER *q, NUMBER *epsilon)
/* /*
* versed sine - this calls qsincos() and discards the value of sin. * versed sine - this calls qsincos() and discards the value of sin.
* *
* This uses the formula: versin(x) = 1 - cos(x). * This uses the formula:
*
* versin(x) = 1 - cos(x)
*/ */
NUMBER * NUMBER *
qversin(NUMBER *q, NUMBER *epsilon) qversin(NUMBER *q, NUMBER *epsilon)
@@ -2006,13 +2008,15 @@ qversin(NUMBER *q, NUMBER *epsilon)
/* /*
* versed cosine - this calls qsincos() and discards the value of cos. * versed cosine - this calls qsincos() and discards the value of cos.
* *
* This uses the formula: vercos(x) = 1 - sin(x). * This uses the formula:
*
* coversin(x) = 1 - sin(x)
*/ */
NUMBER * NUMBER *
qvercos(NUMBER *q, NUMBER *epsilon) qcoversin(NUMBER *q, NUMBER *epsilon)
{ {
NUMBER *sin, *cos, *res; NUMBER *sin, *cos, *res;
NUMBER *vercos; NUMBER *coversin;
long n; long n;
if (qiszero(epsilon)) { if (qiszero(epsilon)) {
@@ -2024,9 +2028,9 @@ qvercos(NUMBER *q, NUMBER *epsilon)
return qlink(&_qzero_); return qlink(&_qzero_);
qsincos(q, n + 2, &sin, &cos); qsincos(q, n + 2, &sin, &cos);
qfree(cos); qfree(cos);
vercos = qsub(&_qone_, sin); coversin = qsub(&_qone_, sin);
qfree(sin); qfree(sin);
res = qmappr(vercos, epsilon, 24); res = qmappr(coversin, epsilon, 24);
qfree(vercos); qfree(coversin);
return res; return res;
} }