Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: implemented the numerical evaluation of the atan2_ function.
  • Loading branch information
cbmarini committed Dec 9, 2025
commit 469d3efa69d6259dfec72f7696e5502c748e8d0f
21 changes: 21 additions & 0 deletions check/features.frm
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,27 @@ assert result("ATAN") =~ expr("
+ 7.85398163397448309615661e-01*atan(1)
")
*--#] evaluate_atan :
*--#[ evaluate_atan2 :
#Startfloat 21d
CFunction atan2;
Local ATAN2 = atan2(0,0)*atan2_(0,0)
+atan2(0,24)*atan2_(0,24)
+atan2(24/13,0)*atan2_(24/13,0)
+atan2(3,-1.45)*atan2_(3,-1.45)
+atan2(0.54321,-1.2345)*atan2_(0.54321,-1.2345)
+atan2(5.4321,-45/11)*atan2_(5.4321,-45/11);
Evaluate;
Print +s;
.end
#pend_if wordsize == 2
assert succeeded?
assert result("ATAN2") =~ expr("
+ 1.57079632679489661923e+00*atan2(24/13,0)
+ 2.72706541948852419832e+00*atan2(5.4321e-01, - 1.2345e+00)
+ 2.21627784862167698618e+00*atan2(5.4321e+00, - 45/11)
+ 2.02102192305561165724e+00*atan2(3, - 1.45e+00)
")
*--#] evaluate_atan2 :
*--#[ evaluate_sqrt :
#Startfloat 21d
CFunction sqrt;
Expand Down
15 changes: 12 additions & 3 deletions sources/evaluate.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
if ( pars[2] == *t ) { /* have to do this one if possible */
TestArgument:
/*
There must be a single argument, except for the AGM function
There must be a single argument, except for the AGM or atan2 functions
*/
tnext = t+t[1]; tt = t+FUNHEAD; NEXTARG(tt);
if( *t == SYMBOL) {
Expand All @@ -397,7 +397,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
first = 0;
goto nextfun;
}
if ( tt != tnext && *t != AGMFUNCTION ) goto nextfun;
if ( tt != tnext && *t != AGMFUNCTION && *t != ATAN2FUNCTION) goto nextfun;
if ( *t == SINFUNCTION ) {
pimul = GetPiArgument(BHEAD t+FUNHEAD);
if ( pimul >= 0 && pimul < 24 ) {
Expand Down Expand Up @@ -511,7 +511,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
}
}

if ( *t == AGMFUNCTION ) {
if ( *t == AGMFUNCTION || *t == ATAN2FUNCTION ) {
if ( GetFloatArgument(BHEAD auxr1,t,1) < 0 ) goto nextfun;
if ( GetFloatArgument(BHEAD auxr3,t,-2) < 0 ) goto nextfun;
}
Expand Down Expand Up @@ -619,6 +619,14 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
mpfr_atan(auxr3,auxr1,RND);
mpfr_mul(auxr2,auxr2,auxr3,RND);
break;
case ATAN2FUNCTION:
nsgn = mpfr_sgn(auxr1);
nsgn2 = mpfr_sgn(auxr3);
// We follow the conventions of mpfr here:
if ( nsgn == 0 && nsgn2 >= 0) goto getout;
mpfr_atan2(auxr3,auxr1,auxr3,RND);
mpfr_mul(auxr2,auxr2,auxr3,RND);
break;
case SINFUNCTION:
mpfr_sin(auxr3,auxr1,RND);
mpfr_mul(auxr2,auxr2,auxr3,RND);
Expand Down Expand Up @@ -653,6 +661,7 @@ int EvaluateFun(PHEAD WORD *term, WORD level, WORD *pars)
case ASINFUNCTION:
case ACOSFUNCTION:
case ATANFUNCTION:
case ATAN2FUNCTION:
case SINHFUNCTION:
case COSHFUNCTION:
case TANHFUNCTION:
Expand Down