Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #include <math.h>
  2.  
  3. double remainder(double numer, double denom)
  4. {
  5.         double res;
  6.         asm("fldl %2;"
  7.                 "fldl %1;"
  8.                 "fprem1;"
  9.                 "fstpl %0;"
  10.                 "fstp %%st;"
  11.         : "=m"(res)
  12.         : "m"(numer), "m"(denom)
  13.         );
  14.         return res;
  15. }
  16. //remainder of 5.3 / 2 is -0.700000
  17. //remainder of 18.5 / 4.2 is 1.700000
  18.  
  19.  
  20.  
  21. double fmod(double numer, double denom)
  22. {
  23.         double res;
  24.         asm("fldl %2;"
  25.                 "fldl %1;"
  26.                 "fprem;"
  27.                 "fstpl %0;"
  28.                 "fstp %%st;"
  29.         : "=m"(res)
  30.         : "m"(numer), "m"(denom)
  31.         );
  32.         return res;
  33. }
  34. // fmod of 5.3 / 2 is 1.300000
  35. // fmod of 18.5 / 4.2 is 1.700000
  36.  
  37.  
  38. double modf(double x, double *intpart)
  39. {
  40.         double res, intp;
  41.         asm("fldl %2;"
  42.                 "fldl %2;"
  43.                 "frndint;"
  44.                 "fstl %1;"
  45.                 "fxch;"
  46.                 "fsubp %%st, %%st(1);"
  47.                 "fstpl %0"
  48.         : "=m"(res), "=m"(intp)
  49.         : "m"(x)
  50.         );
  51.         *intpart = intp;
  52.         return res;
  53. }
  54.  
  55. double ldexp (double x, int expon)
  56. // = x * 2^expot
  57. {
  58.         double res;
  59.         asm("fildl %2;"
  60.                 "fldl %1;"
  61.                 "fscale;"
  62.                 "fstpl %0;"
  63.                 "fstp %%st;"
  64.         : "=m"(res)
  65.         : "m"(x), "m"(expon)
  66.         );
  67.  
  68.         return res;
  69. }
  70.  
  71. double frexp (double x, int* expon)
  72. {
  73.         double res;
  74.         asm("fldl %2;"
  75.                 "fxtract;"
  76.                 "fstpl %0;"
  77.                 "fistpl %1;"
  78.                 "fstp %%st;"
  79.         : "=m"(res), "=m"(*expon)
  80.         : "m"(x)
  81.         );
  82.  
  83. //      *expon = (int)ex;
  84.         return res;
  85. }
  86. // 8.000000 = 0.500000 * 2^ 4
  87.