<font face="'PrimaSans BT,Verdana,sans-serif'">Hi Mirko Scholz,</font><br><br>Thank you for finding and reporting the problem and also providing the<br>test code.  A fix has been made and is now being tested.  It should appear <br>in the next release...<br><br>Cheers,<br>Johnoel<br><br>----- Original Message -----<br>From: Mirko Scholz <mscholz5@gwdg.de><br>Date: Monday, March 7, 2011 9:57 am<br>Subject: [ADMB Users] atan2 for dvariables gives wrong result<br>To: users@admb-project.org<br><br>> Hello,<br>> <br>> the following code gives different results for atan2 depending<br>> if it operates on dvariables or doubles.  The following versions<br>> of ADMB have this issue<br>> <br>>  admb-10.0-linux-gcc4.4.5-64bit<br>>  admb-10.0-linux-gcc4.4.5-64bit<br>> <br>> <br>> #include <fvar.hpp><br>> <br>> int main(void)<br>> {<br>>        independent_variables s(1,2);<br>>     s[1] = -0.977396;<br>>         s[2] = -0.211418;<br>> <br>>  gradient_structure gs;<br>>    dvar_vector ss(1,2);<br>>      ss[1] = s[1];<br>>     ss[2] = s[2];<br>>     // wrong value<br>>    cout<<"atan2(dvariable,dvariable)="<<atan2(ss[1],ss[2])<<endl;<br>> <br>>         dvector st(1,2);<br>>  st[1] = value(ss[1]);<br>>     st[2] = value(ss[2]);<br>>     // correct value<br>>  cout<<"atan2(double,double)="<<atan2(st[1], <br>> st[2])<<endl;<br>> //atan2(dvariable,dvariable)=1.35777<br>> //atan2(double,double)=-1.78382<br>> <br>>      return 0;<br>> }<br>> <br>> I feel not able to fix it directly since my understanding of ADMB<br>> is rather limited currently, but the following workaround fixed <br>> the issue for me<br>> <br>> ph = atan(ss[1]/ss[2]);<br>> if (ss[1]>0 && ss[2]>0) ph = ph; <br>> else if (ss[1]>0 && ss[2]<0) ph = M_PI+ph;<br>> else if (ss[1]<0 && ss[2]<0) ph = ph-M_PI; <br>> else if (ss[1]<0 && ss[2]>0) ph = ph; <br>> // ph = atan2(ss[1], ss[2])<br>> <br>> <br>> Regards<br>> <br>> Mirko Scholz<br>> _______________________________________________<br>> Users mailing list<br>> Users@admb-project.org<br>> http://lists.admb-project.org/mailman/listinfo/users