@@ -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 */
374374TestArgument :
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