Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atan2 incorrect #22

Open
GoogleCodeExporter opened this issue Oct 20, 2015 · 5 comments
Open

atan2 incorrect #22

GoogleCodeExporter opened this issue Oct 20, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 11 Apr 2013 at 4:59

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

The compiler i'm using is MSVC 2008 Express Edition version 9.0

Original comment by [email protected] on 15 Apr 2013 at 11:03

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

sqrt: 113512 atan2: -2147432177

Original comment by [email protected] on 15 Apr 2013 at 1:29

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 4 Feb 2014 at 9:10

Attachments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant