JochiPochi / libfixmath

Automatically exported from code.google.com/p/libfixmath
0 stars 0 forks source link

atan2 incorrect #22

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. angle = fix16_atan2(fix16_one, fix16_sqrt(fix16_from_int(3)));
2.
3.

What is the expected output? What do you see instead?
34314, 51471

What version of the product are you using? On what operating system?
Feb'12 from downloads, Jul'12 from web SVN, Windows

Please provide any additional information below.

Original issue reported on code.google.com by abhishek...@gmail.com on 11 Apr 2013 at 4:59

GoogleCodeExporter commented 8 years ago
I cannot seem to reproduce this bug.

For me the result is 34481, which is 0.5 % error. This is within the expected 
limits.

See attached test.c, I compiled it under x86_64 using GCC with this command:
gcc -o test test.c fix16.c fix16_trig.c fix16_sqrt.c 
./test
sqrt: 113512 atan2: 34481

Original comment by Petteri.Aimonen on 11 Apr 2013 at 3:07

Attachments:

GoogleCodeExporter commented 8 years ago
The compiler i'm using is MSVC 2008 Express Edition version 9.0

Original comment by abhishek...@gmail.com on 15 Apr 2013 at 11:03

GoogleCodeExporter commented 8 years ago
Can you compile the test.c included earlier and tell us its output?

Original comment by Petteri.Aimonen on 15 Apr 2013 at 12:55

GoogleCodeExporter commented 8 years ago
sqrt: 113512 atan2: -2147432177

Original comment by abhishek...@gmail.com on 15 Apr 2013 at 1:29

GoogleCodeExporter commented 8 years ago
I'm also having difficulties with atan2. Here is the code I use to compare 
atan2 for double and Fix16. I cannot expect Fix16 to be as accurate as double, 
but there seems to be an offset of about 0.1 pi for some values. Here is the 
code I use:

#include <cmath>
#include <fstream>
#include <iostream>

#include <fix16.h>
#include <fix16.hpp>

int main()
{
  unsigned int n = 1000;
  std::ofstream file("out.dat");
  std::ostream& out(file);//(std::cout);
  for(unsigned int i = 0; i <= n; i++)
  {
    double d = M_PI/2.*i/1000;
    double s = sin(d);
    double c = cos(d);
    double a = atan2(s,c);
    Fix16 df(d);
    Fix16 sf(df.sin());
    Fix16 cf(df.cos());
    Fix16 af(sf.atan2(cf));
    out << d
        << " " << a
        << " " << (double)af
        << std::endl;
  }
  return 0;
}

I used gnuplot for plotting the results, here is the command:

plot "out.dat" u 1:2 w l title 'double', "out.dat" u 1:3 w l title 'Fix16'

I have attached the plot.

Original comment by avrbegin...@googlemail.com on 4 Feb 2014 at 9:10

Attachments: