Subversion Repositories Kolibri OS

Rev

Rev 5730 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //IO library
  2. #ifndef INCLUDE_MATH_H
  3. #define INCLUDE_MATH_H
  4. #print "[include <math.h>]\n"
  5.  
  6. #ifndef INCLUDE_KOLIBRI_H
  7. #include "../lib/kolibri.h"
  8. #endif
  9.  
  10. :struct MATH
  11. {
  12.         float pi();
  13.         float cos(float x);
  14.         float sin(float x);
  15.         float sqrt(float x);
  16.         float tan(float x);
  17.         float abs(float x);
  18.         float floor(float x);
  19.         signed round(float x);
  20.         signed ceil(float x);
  21.         signed min(signed i1, i2);
  22.         signed max(signed i1, i2);
  23. }math;
  24.  
  25. :signed MATH::round(float x)
  26. {
  27.         x+=0.6;
  28.         return x;
  29. }
  30. :signed MATH::ceil(float x)
  31. {
  32.         dword z;
  33.         float tmp;
  34.         z = x;
  35.         tmp = z;
  36.         IF(tmp<x)z++;
  37.         return z;
  38. }
  39. :float MATH::floor(float x)
  40. {
  41.         signed long z;
  42.         z = x;
  43.         IF(z==x)return x;
  44.         IF(z<0) return z-1;
  45.         return z;
  46. }
  47. :float MATH::abs(float x)
  48. {
  49.         IF(x<0)return -x;
  50.         return x;
  51. }
  52.        
  53. :float MATH::cos(float x)
  54. {
  55.         float r;
  56.         asm
  57.         {
  58.                 fld x
  59.                 fcos
  60.                 fstp r
  61.         }
  62.         return r;
  63. }
  64. :float MATH::sin(float x)
  65. {
  66.         float r;
  67.         asm
  68.         {
  69.                 fld x
  70.                 fsin
  71.                 fstp r
  72.         }
  73.         return r;
  74. }
  75. :float MATH::sqrt(float x)
  76. {
  77.         float r;
  78.         asm
  79.         {
  80.                 fld x
  81.                 fsqrt
  82.                 fstp r
  83.         }
  84.         return r;
  85. }
  86. :float MATH::tan(float x)
  87. {
  88.         float r;
  89.         asm
  90.         {
  91.                 fld x
  92.                 fld1
  93.                 fpatan
  94.                 fstp r
  95.         }
  96.         return r;
  97. }
  98. :signed MATH::min(signed i1, i2)
  99. {
  100.         if (i1 < i2)
  101.                 return i1;
  102.         else
  103.                 return i2;
  104. }
  105. :signed MATH::max(signed i1, i2)
  106. {
  107.         if (i1 > i2)
  108.                 return i1;
  109.         else
  110.                 return i2;
  111. }
  112. #endif