Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Rocket Forces
  2.  * Filename: mymath.h
  3.  * Version 0.1
  4.  * Copyright (c) Serial 2007
  5.  */
  6.  
  7.  
  8. extern "C" int _fltused = 0;
  9.  
  10. #define M_PI 3.14159265358979323846
  11.  
  12. inline double sin(double x)
  13. {
  14.         __asm   fld     x
  15.         __asm   fsin
  16. }
  17.  
  18. inline double cos(double x)
  19. {
  20.         __asm   fld     x
  21.         __asm   fcos
  22. }
  23.  
  24. inline double sqrt(double x)
  25. {
  26.         __asm   fld     x
  27.         __asm   fsqrt
  28. }
  29.  
  30. inline double acos(double x)
  31. {
  32.         __asm   fld x
  33.         __asm   fld st(0)
  34.         __asm   fmul st,st(1)
  35.         __asm   fld1
  36.         __asm   fsubrp st(1),st(0)
  37.         __asm   fsqrt
  38.         __asm   fxch st(1)
  39.         __asm   fpatan
  40. }
  41.  
  42. inline double atan(double x)
  43. {
  44.         double res = acos(1 / sqrt(1 + x * x));
  45.         if (x < 0)
  46.         {
  47.                 res *= -1;
  48.         }
  49.         return res;
  50. }
  51.  
  52. inline int round_int(double x)
  53. {
  54.         int i;
  55.         static const float round_to_nearest = 0.5f;
  56.         __asm
  57.         {
  58.                 fld      x
  59.                 fadd     st, st(0)
  60.                 fadd     round_to_nearest
  61.                 fistp    i
  62.                 sar      i, 1
  63.         }
  64.         return i;
  65. }
  66.  
  67. inline int floor_int(double x)
  68. {
  69.         int i;
  70.         static const float round_toward_m_i = -0.5f;
  71.         __asm
  72.         {
  73.                 fld      x
  74.                 fadd     st, st (0)
  75.                 fadd     round_toward_m_i
  76.                 fistp    i
  77.                 sar      i, 1
  78.         }
  79.         return i;
  80. }
  81.  
  82. inline int ceil_int(double x)
  83. {
  84.         int i;
  85.         static const float round_toward_p_i = -0.5f;
  86.         __asm
  87.         {
  88.                 fld      x
  89.                 fadd     st, st (0)
  90.                 fsubr    round_toward_p_i
  91.                 fistp    i
  92.                 sar      i, 1
  93.         }
  94.         return (-i);
  95. }
  96.