Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PI_FLOAT 3.14159265f
- #define PIBY2_FLOAT 1.5707963f
- float fabsf(float x)
- {
- union float2int
- {
- int i;
- float f;
- } f2i;
- f2i.f = x;
- f2i.i &= 0x7FFFFFFF;
- return f2i.f;
- }
- float arctan2(float y, float x)
- {
- float atan, z;
- if(x == 0.0f)
- {
- if(y > 0.0f)
- return PIBY2_FLOAT;
- if(y == 0.0f)
- return 0.0f;
- return -PIBY2_FLOAT;
- }
- z = y/x;
- if([self fabsf:z] < 1.0f)
- {
- atan = z/(1.0f + 0.28f*z*z);
- if(x < 0.0f)
- {
- if(y < 0.0f)
- return atan - PI_FLOAT;
- return atan + PI_FLOAT;
- }
- }
- else
- {
- atan = PIBY2_FLOAT - z/(z*z + 0.28f);
- if(y < 0.0f)
- return atan - PI_FLOAT;
- }
- return atan;
- }
Add Comment
Please, Sign In to add comment