[haiku-bugs] [Haiku] #14933: atan2 returns wrong result in some case

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Tue, 26 Feb 2019 19:00:29 -0000

#14933: atan2 returns wrong result in some case
-----------------------+------------------------------
 Reporter:  hanya      |        Owner:  nobody
     Type:  bug        |       Status:  new
 Priority:  normal     |    Milestone:  Unscheduled
Component:  - General  |      Version:  R1/Development
 Keywords:             |   Blocked By:
 Blocking:             |  Has a Patch:  0
 Platform:  x86-64     |
-----------------------+------------------------------
 atan2 C function returns wrong result in the following case.

 {{{
 // atan2.c
 #include <math.h>
 #include <stdio.h>

 int main(int argc, char* argv[]) {
     // from Python/Lib/test/cmath_testcases.txt acos0200
     // acos0200 acos 1.6206860518683021e+308 1.0308426226285283e+308 ->
     // 0.56650826093826223 -710.54206874241561

     double real = 1.6206860518683021e+308;
     double imag = 1.0308426226285283e+308;
     double r = atan2(imag, real); // real part
     printf("expected: 0.56650826093826223\n");
     printf("  result: %1.17lf\n", r);
     //x86_64, result: 0.08332244049906361
 }

 // gcc -o atan2 atan2.c -g -O0
 }}}

 Python contains some test cases for its complex calculations.
 It contains near infinity acos0200 test executed by test_cmath.
 The test can be executed as follows:
 {{{
 python -m test test_cmath
 }}}
 The same calculation in the Python interactive:
 {{{

import cmath
c = complex(1.6206860518683021e+308, 1.0308426226285283e+308)
cmath.acos(c)
 (0.08332244049906361-710.5420687424156j)
 }}}
 The imaginary part is correct.

 The calculation of the cmath.acos is done by cmath_acos_impl function in
 Modules/cmathmodule.c.
 The real part is calculated as follows:

 {{{
 r.real = atan2(fabs(z.imag), z.real);
 }}}

 fabs call is removed from the C code above since the value is positive.

 The result on the x86_gcc2(Python2) and secondary x86(Python3) are
 correct.

-- 
Ticket URL: <https://dev.haiku-os.org/ticket/14933>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: