home *** CD-ROM | disk | FTP | other *** search
/ ANews 3 / AnewsCD3.iso / DP / Programmation / GCC / gcc_include / math.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-08  |  4.4 KB  |  237 lines

  1. /*    math functions for ansic.library    */
  2. /*    (c)Copyright 1992 Davide Pasetto     */
  3.  
  4. #ifndef    _MATH_H
  5. #define _MATH_H
  6.  
  7. #include    <sys/errno.h>
  8.  
  9. /* the functions prototypes */
  10.  
  11. #ifdef    __cplusplus
  12. extern "C" {
  13. #endif
  14.  
  15. extern double const fmod(double, double);
  16. extern double modf(double, double *);
  17. extern double frexp(double, int *);
  18. extern double const IEEEDPAbs(double);
  19. extern double const IEEEDPFloor(double);
  20. extern double const IEEEDPCeil(double);
  21. extern double const IEEEDPTan(double);
  22. extern double const IEEEDPAtan(double);
  23. extern double const IEEEDPCos(double);
  24. extern double const IEEEDPACos(double);
  25. extern double const IEEEDPSin(double);
  26. extern double const IEEEDPASin(double);
  27. extern double const IEEEDPExp(double);
  28. extern double const IEEEDPPow(double,double);
  29. extern double const IEEEDPLog(double);
  30. extern double const IEEEDPLog10(double);
  31. extern double const IEEEDPTanh(double);
  32. extern double const IEEEDPCosh(double);
  33. extern double const IEEEDPSinh(double);
  34. extern double const IEEEDPSqrt(double);
  35.  
  36. #ifdef    __cplusplus
  37. }
  38. #endif
  39.  
  40.  
  41. #ifdef    __cplusplus
  42.  
  43. static const double    PI = 3.141592653589793;
  44. static const double    M_PI = 3.141592653589793;
  45. static const double    TWO_PI = 2*PI;
  46. static const double    PI2    = PI/2.0;
  47. static const double    PI4    = PI/4.0;
  48. static const double    E = 2.718281828459045;
  49. static const double    M_E = 2.718281828459045;
  50. static const double    LOG10 = 2.302585092994046;
  51. static const double    FPTEN = 10.0;
  52. static const double    FPONE = 1.0;
  53. static const double    FPHALF = 0.5;
  54. static const double    FPZERO = 0.0;
  55. static const double     HUGE = 1.0e300;
  56.  
  57. #else    /* not __cplusplus */
  58.  
  59. #define PI        ((double)3.141592653589793)
  60. #define M_PI        ((double)3.141592653589793)
  61. #define TWO_PI        (((double)2)* PI)
  62. #define PI2        (PI/((double)2))
  63. #define PI4        (PI/((double)4))
  64. #define    E        ((double)2.718281828459045)
  65. #define    M_E        ((double)2.718281828459045)
  66. #define LOG10        ((double)2.302585092994046)
  67. #define FPTEN        ((double)10.0)
  68. #define    FPONE        ((double)1.0)
  69. #define FPHALF        ((double)0.5)
  70. #define FPZERO        ((double)0.0)
  71. #define HUGE            ((double)1.0e300)
  72.  
  73. #endif /* __cplusplus */
  74.  
  75.  
  76. /* now define c functions in term of library calls */
  77.  
  78. extern inline const double fabs(double d)
  79. {
  80.   return IEEEDPAbs(d);
  81. }
  82.  
  83. extern inline const double floor(double d)
  84. {
  85.   return IEEEDPFloor(d);
  86. }
  87.  
  88. extern inline const double ceil(double d)
  89. {
  90.   return IEEEDPCeil(d);
  91. }
  92.  
  93. extern inline const double tan(double d)
  94. {
  95.   return IEEEDPTan(d);
  96. }
  97.  
  98. extern inline const double atan(double d)
  99. {
  100.   return IEEEDPAtan(d);
  101. }
  102.  
  103. extern inline const double cos(double d)
  104. {
  105.   return IEEEDPCos(d);
  106. }
  107.  
  108. extern inline const double acos(double d)
  109. {
  110.   return IEEEDPACos(d);
  111. }
  112.  
  113. extern inline const double sin(double d)
  114. {
  115.   return IEEEDPSin(d);
  116. }
  117.  
  118. extern inline const double asin(double d)
  119. {
  120.   return IEEEDPASin(d);
  121. }
  122.  
  123. extern inline const double exp(double d)
  124. {
  125.   return IEEEDPExp(d);
  126. }
  127.  
  128. extern inline const double pow(double a,double b)
  129. {
  130.   return IEEEDPPow(b,a);
  131. }
  132.  
  133. extern inline const double log(double a)
  134. {
  135.   return IEEEDPLog(a);
  136. }
  137.  
  138. extern inline const double log10(double a)
  139. {
  140.   return IEEEDPLog10(a);
  141. }
  142.  
  143. extern inline const double sqrt(double a)
  144. {
  145.   return IEEEDPSqrt(a);
  146. }
  147.  
  148. extern inline const double sinh(double a)
  149. {
  150.   return IEEEDPSinh(a);
  151. }
  152.  
  153. extern inline const double cosh(double a)
  154. {
  155.   return IEEEDPCosh(a);
  156. }
  157.  
  158. extern inline const double tanh(double a)
  159. {
  160.   return IEEEDPTanh(a);
  161. }
  162.  
  163. extern inline const int trunc(double x)
  164. {
  165.   return (int)(x);
  166. }
  167.  
  168. extern inline const int round(double x)
  169. {
  170.   return (int)((x) + 0.5);
  171. }
  172.  
  173. extern inline const double itof(int i)
  174. {
  175.   return (double)(i);
  176. }
  177.  
  178. extern inline const double ldexp(double a,int b)
  179. {
  180.   return a*pow(2.0,b);
  181. }
  182.  
  183. extern inline const int abs(int x)
  184. {
  185.   return ((x)<0?-(x):(x));
  186. }
  187.  
  188. extern inline const double atan2(const double y, const double x)
  189. {
  190.   if(x > 0) {
  191.     if (y > 0) {
  192.       if (x > y)
  193.     return atan (y/x);
  194.       else
  195.     return (PI2 - atan(x/y));
  196.     }
  197.     else {
  198.       if (x > -y)
  199.     return atan (y / x);
  200.       else
  201.     return - PI2 - atan (x / y);
  202.     }
  203.   }
  204.   else {
  205.     if (y > 0) {
  206.       if (-x > y)
  207.     return PI + atan (y / x);
  208.       else
  209.     return PI2 - atan (x / y);
  210.     }
  211.     else {
  212.       if (-x > -y)
  213.     return - PI + atan (y / x);
  214.       else if (y < 0)
  215.     return - PI2 - atan (x / y);
  216.       else {
  217.     union {
  218.       unsigned long i[2];
  219.       double        val;
  220.     } value;
  221.     
  222.     value.i[0] = 0x7fffffff;
  223.     value.i[1] = 0xffffffff;
  224.     return value.val;
  225.       }
  226.     }
  227.   }
  228. }
  229.  
  230. extern inline const double hypot (const double x, const double y)
  231. {
  232.   return sqrt (x*x + y*y);
  233. }
  234.  
  235.  
  236. #endif    /* _MATH_H */
  237.