Guest User

Untitled

a guest
Jun 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #define PI_FLOAT 3.14159265f
  2. #define PIBY2_FLOAT 1.5707963f
  3.  
  4. float fabsf(float x)
  5. {
  6. union float2int
  7. {
  8. int i;
  9. float f;
  10. } f2i;
  11.  
  12. f2i.f = x;
  13. f2i.i &= 0x7FFFFFFF;
  14.  
  15. return f2i.f;
  16. }
  17.  
  18. float arctan2(float y, float x)
  19. {
  20. float atan, z;
  21.  
  22. if(x == 0.0f)
  23. {
  24. if(y > 0.0f)
  25. return PIBY2_FLOAT;
  26.  
  27. if(y == 0.0f)
  28. return 0.0f;
  29.  
  30. return -PIBY2_FLOAT;
  31. }
  32.  
  33. z = y/x;
  34.  
  35. if([self fabsf:z] < 1.0f)
  36. {
  37. atan = z/(1.0f + 0.28f*z*z);
  38.  
  39. if(x < 0.0f)
  40. {
  41. if(y < 0.0f)
  42. return atan - PI_FLOAT;
  43.  
  44. return atan + PI_FLOAT;
  45. }
  46. }
  47. else
  48. {
  49. atan = PIBY2_FLOAT - z/(z*z + 0.28f);
  50.  
  51. if(y < 0.0f)
  52. return atan - PI_FLOAT;
  53. }
  54.  
  55. return atan;
  56. }
Add Comment
Please, Sign In to add comment