Subversion Repositories Kolibri OS

Rev

Rev 5676 | 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. }math;
  22. :signed MATH::round(float x)
  23. {
  24.         x+=0.6;
  25.         return x;
  26. }
  27. :signed MATH::ceil(float x)
  28. {
  29.         dword z;
  30.         float tmp;
  31.         z = x;
  32.         tmp = z;
  33.         IF(tmp<x)z++;
  34.         return z;
  35. }
  36. :float MATH::floor(float x)
  37. {
  38.         signed long z;
  39.         z = x;
  40.         IF(z==x)return x;
  41.         IF(z<0) return z-1;
  42.         return z;
  43. }
  44. :float MATH::abs(float x)
  45. {
  46.         IF(x<0)return -x;
  47.         return x;
  48. }
  49.        
  50. :float MATH::cos(float x)
  51. {
  52.         float r;
  53.         asm
  54.         {
  55.                 fld x
  56.                 fcos
  57.                 fstp r
  58.         }
  59.         return r;
  60. }
  61. :float MATH::sin(float x)
  62. {
  63.         float r;
  64.         asm
  65.         {
  66.                 fld x
  67.                 fsin
  68.                 fstp r
  69.         }
  70.         return r;
  71. }
  72. :float MATH::sqrt(float x)
  73. {
  74.         float r;
  75.         asm
  76.         {
  77.                 fld x
  78.                 fsqrt
  79.                 fstp r
  80.         }
  81.         return r;
  82. }
  83. :float MATH::tan(float x)
  84. {
  85.         float r;
  86.         asm
  87.         {
  88.                 fld x
  89.                 fld1
  90.                 fpatan
  91.                 fstp r
  92.         }
  93.         return r;
  94. }
  95. #endif