math.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include <bbMath.h>
  2. #define RAD_TO_DEG 57.2957795130823208767981548141052
  3. #define DEG_TO_RAD 0.0174532925199432957692369076848861
  4. #if __STDC_VERSION__ >= 199901L
  5. extern int bbIsNan( double x );
  6. extern int bbIsInf( double x );
  7. extern double bbSqr( double x );
  8. extern double bbSin( double x );
  9. extern double bbCos( double x );
  10. extern double bbTan( double x );
  11. extern double bbASin( double x );
  12. extern double bbACos( double x );
  13. extern double bbATan( double x );
  14. extern double bbATan2( double y,double x );
  15. extern double bbSinh( double x );
  16. extern double bbCosh( double x );
  17. extern double bbTanh( double x );
  18. extern double bbExp( double x );
  19. extern double bbFloor( double x );
  20. extern double bbLog( double x );
  21. extern double bbLog10( double x );
  22. extern double bbCeil( double x );
  23. extern double bbRound( double x );
  24. extern double bbTrunc( double x );
  25. extern int bbIsNanf( float x );
  26. extern int bbIsInff( float x );
  27. extern float bbSqrf( float x );
  28. extern float bbSinf( float x );
  29. extern float bbCosf( float x );
  30. extern float bbTanf( float x );
  31. extern float bbASinf( float x );
  32. extern float bbACosf( float x );
  33. extern float bbATanf( float x );
  34. extern float bbATan2f( float y,float x );
  35. extern float bbSinhf( float x );
  36. extern float bbCoshf( float x );
  37. extern float bbTanhf( float x );
  38. extern float bbExpf( float x );
  39. extern float bbFloorf( float x );
  40. extern float bbLogf( float x );
  41. extern float bbLog10f( float x );
  42. extern float bbCeilf( float x );
  43. extern float bbRoundf( float x );
  44. extern float bbTruncf( float x );
  45. #else
  46. int bbIsNan( double x ){
  47. return isnan(x) ? 1 : 0;
  48. }
  49. int bbIsInf( double x ){
  50. return isinf(x) ? 1 : 0;
  51. }
  52. double bbSqr( double x ){
  53. return sqrt( x );
  54. }
  55. double bbSin( double x ){
  56. return sin( x*DEG_TO_RAD );
  57. }
  58. double bbCos( double x ){
  59. return cos( x*DEG_TO_RAD );
  60. }
  61. double bbTan( double x ){
  62. return tan( x*DEG_TO_RAD );
  63. }
  64. double bbASin( double x ){
  65. return asin( x ) * RAD_TO_DEG;
  66. }
  67. double bbACos( double x ){
  68. return acos( x ) * RAD_TO_DEG;
  69. }
  70. double bbATan( double x ){
  71. return atan( x ) * RAD_TO_DEG;
  72. }
  73. double bbATan2( double y,double x ){
  74. return atan2( y,x ) * RAD_TO_DEG;
  75. }
  76. double bbSinh( double x ){
  77. return sinh( x );
  78. }
  79. double bbCosh( double x ){
  80. return cosh( x );
  81. }
  82. double bbTanh( double x ){
  83. return tanh( x );
  84. }
  85. double bbExp( double x ){
  86. return exp( x );
  87. }
  88. double bbFloor( double x ){
  89. return floor( x );
  90. }
  91. double bbLog( double x ){
  92. return log(x);
  93. }
  94. double bbLog10( double x ){
  95. return log10(x);
  96. }
  97. double bbCeil( double x ){
  98. return ceil( x );
  99. }
  100. double bbRound( double x ){
  101. return round( x );
  102. }
  103. double bbTrunc( double x ){
  104. return trunc( x );
  105. }
  106. #define RAD_TO_DEGF RAD_TO_DEG
  107. #define DEG_TO_RADF DEG_TO_RAD
  108. #define sqrtf sqrt
  109. #define sinf sin
  110. #define cosf cos
  111. #define tanf tan
  112. #define asinf asin
  113. #define acosf acos
  114. #define atanf atan
  115. #define atan2f atan2
  116. #define sinhf sinh
  117. #define coshf cosh
  118. #define tanhf tanh
  119. #define expf exp
  120. #define floorf floor
  121. #define logf log
  122. #define log10f log10
  123. #define ceilf ceil
  124. #define roundf round
  125. #define truncf trunc
  126. float bbSqrf( float x ){
  127. return sqrtf( x );
  128. }
  129. float bbSinf( float x ){
  130. return sinf( x*DEG_TO_RADF );
  131. }
  132. float bbCosf( float x ){
  133. return cosf( x*DEG_TO_RADF );
  134. }
  135. float bbTanf( float x ){
  136. return tanf( x*DEG_TO_RADF );
  137. }
  138. float bbASinf( float x ){
  139. return asinf( x ) * RAD_TO_DEGF;
  140. }
  141. float bbACosf( float x ){
  142. return acosf( x ) * RAD_TO_DEGF;
  143. }
  144. float bbATanf( float x ){
  145. return atanf( x ) * RAD_TO_DEGF;
  146. }
  147. float bbATan2f( float y,float x ){
  148. return atan2f( y,x ) * RAD_TO_DEGF;
  149. }
  150. float bbSinhf( float x ){
  151. return sinhf( x );
  152. }
  153. float bbCoshf( float x ){
  154. return coshf( x );
  155. }
  156. float bbTanhf( float x ){
  157. return tanhf( x );
  158. }
  159. float bbExpf( float x ){
  160. return expf( x );
  161. }
  162. float bbFloorf( float x ){
  163. return floorf( x );
  164. }
  165. float bbLogf( float x ){
  166. return logf(x);
  167. }
  168. float bbLog10f( float x ){
  169. return log10f(x);
  170. }
  171. float bbCeilf( float x ){
  172. return ceilf( x );
  173. }
  174. float bbRoundf( float x ){
  175. return roundf( x );
  176. }
  177. float bbTruncf( float x ){
  178. return truncf( x );
  179. }
  180. #endif