Reputation: 3941
I am going over someone else's code written a few years ago which is pretty badly documented. At one point there is the following code snippet:
#define BINARYPOINT 16
....
float x;
int y;
int z;
....
....
//x has new values now
y = (int) (x*(1<<BINARYPOINT));
z = arctan2(y);
x = z;
In the code y is being explicitly used to compute the arctan of it, function arctan takes an int and gives the arctan of it which is another int. Now my trouble is here, I don't see how computing the arctan of x*(1<<BINARYPOINT)
will give me the arctan of x?
Can anybody please explain what is going on here?
Thanks a lot in advance.
Upvotes: 2
Views: 169
Reputation: 3849
That code is doing Binary Scaling. The floating point number is converted to an integer representation with a B16 binary scale, and then the function arctan2
is called. This is a routine that takes an integer argument and knows that it is using a B16 scale factor. It's not the standard atan
call that takes a double
argument.
Note that the name of the function, arctan2
, makes it look like it's intended to be the two argument version of the arctan, so you should check into that and make sure you're making the right call.
Upvotes: 4