Issue 22 in libfixmath: atan2 incorrect

27 views
Skip to first unread message

libfi...@googlecode.com

unread,
Apr 11, 2013, 12:59:56 AM4/11/13
to libfi...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 22 by abhishek...@gmail.com: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

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.



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

libfi...@googlecode.com

unread,
Apr 11, 2013, 11:07:56 AM4/11/13
to libfi...@googlegroups.com

Comment #1 on issue 22 by Petteri.Aimonen: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

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



Attachments:
test.c 189 bytes

libfi...@googlecode.com

unread,
Apr 15, 2013, 7:04:02 AM4/15/13
to libfi...@googlegroups.com

Comment #2 on issue 22 by abhishek...@gmail.com: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

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

libfi...@googlecode.com

unread,
Apr 15, 2013, 8:55:34 AM4/15/13
to libfi...@googlegroups.com

Comment #3 on issue 22 by Petteri.Aimonen: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

Can you compile the test.c included earlier and tell us its output?

libfi...@googlecode.com

unread,
Apr 15, 2013, 9:29:31 AM4/15/13
to libfi...@googlegroups.com

Comment #4 on issue 22 by abhishek...@gmail.com: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

sqrt: 113512 atan2: -2147432177

libfi...@googlecode.com

unread,
Feb 4, 2014, 4:10:38 AM2/4/14
to libfi...@googlegroups.com

Comment #5 on issue 22 by avrbegin...@googlemail.com: atan2 incorrect
http://code.google.com/p/libfixmath/issues/detail?id=22

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.

Attachments:
doubleVsFix16.png 24.9 KB
Reply all
Reply to author
Forward
0 new messages