Open GoogleCodeExporter opened 9 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:
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
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
sqrt: 113512 atan2: -2147432177
Original comment by abhishek...@gmail.com
on 15 Apr 2013 at 1:29
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:
Original issue reported on code.google.com by
abhishek...@gmail.com
on 11 Apr 2013 at 4:59