Listing 8: atan2()


UDouble<is_correlated>  atan2(const  UDouble<is_correlated>&  arg1,
                              const  UDouble<is_correlated>&  arg2)
{
   UDouble<is_correlated>  retval;
   double  slope1  =  1.0,  slope2  =  1.0;
   double  sum2  =  arg2.value  *  arg2.value  +  arg1.value  *  arg1.value;
   
   if  (sum2  !=  0.0)
   {
       slope1  =  arg2.value  /  sum2;
       slope2  =  -arg1.value  /  sum2;
   }
   if  (is_correlated)
       retval.uncertainty  =  slope1  *  arg1.uncertainty
                           +  slope2  *  arg2.uncertainty;
   else
       retval.uncertainty  =  hypot(slope1  *  arg1.uncertainty,
                                    slope2  *  arg2.uncertainty);
   retval.value  =  atan2(arg1.value,  arg2.value);
   return  retval;
}
//End of File