Skip to content

Commit 80b0f5d

Browse files
committed
feat: implemented the numerical evaluation of the atan2_ function.
1 parent 6d951d8 commit 80b0f5d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

check/features.frm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,27 @@ assert result("ATAN") =~ expr("
12251225
+ 7.85398163397448309615661e-01*atan(1)
12261226
")
12271227
*--#] evaluate_atan :
1228+
*--#[ evaluate_atan2 :
1229+
#Startfloat 21d
1230+
CFunction atan2;
1231+
Local ATAN2 = atan2(0,0)*atan2_(0,0)
1232+
+atan2(0,24)*atan2_(0,24)
1233+
+atan2(24/13,0)*atan2_(24/13,0)
1234+
+atan2(3,-1.45)*atan2_(3,-1.45)
1235+
+atan2(0.54321,-1.2345)*atan2_(0.54321,-1.2345)
1236+
+atan2(5.4321,-45/11)*atan2_(5.4321,-45/11);
1237+
Evaluate;
1238+
Print +s;
1239+
.end
1240+
#pend_if wordsize == 2
1241+
assert succeeded?
1242+
assert result("ATAN2") =~ expr("
1243+
+ 1.57079632679489661923e+00*atan2(24/13,0)
1244+
+ 2.72706541948852419832e+00*atan2(5.4321e-01, - 1.2345e+00)
1245+
+ 2.21627784862167698618e+00*atan2(5.4321e+00, - 45/11)
1246+
+ 2.02102192305561165724e+00*atan2(3, - 1.45e+00)
1247+
")
1248+
*--#] evaluate_atan2 :
12281249
*--#[ evaluate_sqrt :
12291250
#Startfloat 21d
12301251
CFunction sqrt;

sources/evaluate.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
373373
if ( pars[2] == *t ) { /* have to do this one if possible */
374374
TestArgument:
375375
/*
376-
There must be a single argument, except for the AGM function
376+
There must be a single argument, except for the AGM or atan2 functions
377377
*/
378378
tnext = t+t[1]; tt = t+FUNHEAD; NEXTARG(tt);
379379
if( *t == SYMBOL) {
@@ -397,7 +397,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
397397
first = 0;
398398
goto nextfun;
399399
}
400-
if ( tt != tnext && *t != AGMFUNCTION ) goto nextfun;
400+
if ( tt != tnext && *t != AGMFUNCTION && *t != ATAN2FUNCTION) goto nextfun;
401401
if ( *t == SINFUNCTION ) {
402402
pimul = GetPiArgument(BHEAD t+FUNHEAD);
403403
if ( pimul >= 0 && pimul < 24 ) {
@@ -511,7 +511,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
511511
}
512512
}
513513

514-
if ( *t == AGMFUNCTION ) {
514+
if ( *t == AGMFUNCTION || *t == ATAN2FUNCTION ) {
515515
if ( GetFloatArgument(BHEAD auxr1,t,1) < 0 ) goto nextfun;
516516
if ( GetFloatArgument(BHEAD auxr3,t,-2) < 0 ) goto nextfun;
517517
}
@@ -619,6 +619,14 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
619619
mpfr_atan(auxr3,auxr1,RND);
620620
mpfr_mul(auxr2,auxr2,auxr3,RND);
621621
break;
622+
case ATAN2FUNCTION:
623+
nsgn = mpfr_sgn(auxr1);
624+
nsgn2 = mpfr_sgn(auxr3);
625+
// We follow the conventions of mpfr here:
626+
if ( nsgn == 0 && nsgn2 >= 0) goto getout;
627+
mpfr_atan2(auxr3,auxr1,auxr3,RND);
628+
mpfr_mul(auxr2,auxr2,auxr3,RND);
629+
break;
622630
case SINFUNCTION:
623631
mpfr_sin(auxr3,auxr1,RND);
624632
mpfr_mul(auxr2,auxr2,auxr3,RND);
@@ -653,6 +661,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
653661
case ASINFUNCTION:
654662
case ACOSFUNCTION:
655663
case ATANFUNCTION:
664+
case ATAN2FUNCTION:
656665
case SINHFUNCTION:
657666
case COSHFUNCTION:
658667
case TANHFUNCTION:

0 commit comments

Comments
 (0)