Example #1
0
/*

	for large input values use :

	arctan(x) =  (PI / 2) - arctan(1 / |x|)   

	and sign of result = sign of original input 

*/
void	M_arctan_large_input(M_APM rr, int places, M_APM xx)
{
M_APM	tmp1, tmp2;

tmp1 = M_get_stack_var();
tmp2 = M_get_stack_var();

M_check_PI_places(places);

m_apm_divide(tmp1, (places + 6), MM_One, xx);   	   /*  1 / xx       */
tmp1->m_apm_sign = 1;					   /* make positive */
m_apm_arctan(tmp2, (places + 6), tmp1);
m_apm_subtract(tmp1, MM_lc_HALF_PI, tmp2);
m_apm_round(rr, places, tmp1);

rr->m_apm_sign = xx->m_apm_sign;			  /* fix final sign */

M_restore_stack(2);
}
Example #2
0
void	m_apm_arctan2(M_APM rr, int places, M_APM yy, M_APM xx)
{
M_APM   tmp5, tmp6, tmp7;
int	ix, iy;

iy = yy->m_apm_sign;
ix = xx->m_apm_sign;

if (ix == 0)       /* x == 0 */
  {
   if (iy == 0)    /* y == 0 */
     {
      M_apm_log_error_msg(M_APM_RETURN, "\'m_apm_arctan2\', Both Inputs = 0");
      M_set_to_zero(rr);
      return;
     }

   M_check_PI_places(places);
   m_apm_round(rr, places, MM_lc_HALF_PI);
   rr->m_apm_sign = iy;
   return;
  }

if (iy == 0)
  {
   if (ix == 1)
     {
      M_set_to_zero(rr);
     }
   else
     {
      M_check_PI_places(places);
      m_apm_round(rr, places, MM_lc_PI);
     } 

   return;
  }

/*
 *    the special cases have been handled, now do the real work
 */

tmp5 = M_get_stack_var();
tmp6 = M_get_stack_var();
tmp7 = M_get_stack_var();

m_apm_divide(tmp6, (places + 6), yy, xx);
m_apm_arctan(tmp5, (places + 6), tmp6);

if (ix == 1)         /* 'x' is positive */
  {
   m_apm_round(rr, places, tmp5);
  }
else                 /* 'x' is negative */
  {
   M_check_PI_places(places);

   if (iy == 1)      /* 'y' is positive */
     {
      m_apm_add(tmp7, tmp5, MM_lc_PI);
      m_apm_round(rr, places, tmp7);
     }
   else              /* 'y' is negative */
     {
      m_apm_subtract(tmp7, tmp5, MM_lc_PI);
      m_apm_round(rr, places, tmp7);
     }
  }

M_restore_stack(3);
}
Example #3
0
void	m_apm_arctan_mt(M_APM rr, int places, M_APM aa)
{
	m_apm_enter();
	m_apm_arctan(rr,places,aa);
	m_apm_leave();
}