summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-02 11:43:49 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-02-02 11:43:49 +0000
commit5df2cc3b25bd675b201e0c17ab44ffa562610396 (patch)
treea8f043d22f0aa7da1517ff554b45fbf193a845c0
parent684442d308ec7789fe38697e810b4c4fe9a6c0e0 (diff)
Implement some of the circular function.
-rw-r--r--apl9.h1
-rw-r--r--functions.c50
2 files changed, 49 insertions, 2 deletions
diff --git a/apl9.h b/apl9.h
index 947d58c..3b77423 100644
--- a/apl9.h
+++ b/apl9.h
@@ -328,6 +328,7 @@ Array *fnTimes(Array *, Array *);
Array *fnDivide(Array *, Array *);
Array *fnPower(Array *, Array *);
Array *fnLogarithm(Array *, Array *);
+Array *fnCircular(Array *, Array *);
Array *fnBinomial(Array *, Array *);
Array *fnDeal(Array *, Array *);
Array *fnResidue(Array *, Array *);
diff --git a/functions.c b/functions.c
index 68dcbe7..e3020f9 100644
--- a/functions.c
+++ b/functions.c
@@ -70,7 +70,7 @@ fndyad dyadfunctiondefs[] = {
fnPower, /* * */
fnLogarithm, /* ⍟ */
0, /* ⌹ */
- 0, /* ○ */
+ fnCircular, /* ○ */
fnBinomial, /* ! */
fnDeal, /* ? */
fnResidue, /* | */
@@ -982,6 +982,52 @@ SCALAR_FUNCTION_2(fnLogarithm, 1, left->type,
break;
)
+SCALAR_FUNCTION_2(fnCircular, 1, AtypeFloat,
+ case AtypeFloat:{
+ double v = right->floatdata[i];
+ double r = 0;
+ switch((vlong)left->floatdata[i]){
+ case 0:
+ r = sqrt(1-v*v);
+ break;
+ case 1:
+ r = sin(v);
+ break;
+ case -1:
+ r = asin(v);
+ break;
+ case 2:
+ r = cos(v);
+ break;
+ case -2:
+ r = acos(v);
+ break;
+ case 3:
+ r = tan(v);
+ break;
+ case -3:
+ r = atan(v);
+ break;
+ case 4:
+ r = sqrt(1+v*v);
+ break;
+ case -4:
+ if(v == 0)
+ throwerror(nil, EDomain);
+ if(v == -1)
+ r = 0;
+ else
+ r = (v+1)*sqrt((v-1)/(v+1));
+ break;
+ default:
+ throwerror(nil, EDomain);
+ }
+ res->floatdata[i] = r;
+ }
+ break;
+)
+
+
SCALAR_FUNCTION_2(fnBinomial, 0, AtypeFloat,
case AtypeInt:
if(left->intdata[i] > right->intdata[i])
@@ -1845,4 +1891,4 @@ indexOfHelper(Array *left, Array *right, int interval)
freearray(rightshape);
freearray(right);
return result;
-} \ No newline at end of file
+}