Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

537 lines
18 KiB

  1. /***
  2. *math.h - definitions and declarations for math library
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * This file contains constant definitions and external subroutine
  8. * declarations for the math subroutine library.
  9. * [ANSI/System V]
  10. *
  11. * [Public]
  12. *
  13. ****/
  14. #if _MSC_VER > 1000
  15. #pragma once
  16. #endif
  17. #ifndef _INC_MATH
  18. #define _INC_MATH
  19. #if !defined(_WIN32)
  20. #error ERROR: Only Win32 target supported!
  21. #endif
  22. #ifdef _MSC_VER
  23. /*
  24. * Currently, all MS C compilers for Win32 platforms default to 8 byte
  25. * alignment.
  26. */
  27. #pragma pack(push,8)
  28. #endif /* _MSC_VER */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #ifndef __assembler /* Protect from assembler */
  33. /* Define _CRTIMP */
  34. #ifndef _CRTIMP
  35. #ifdef _DLL
  36. #define _CRTIMP __declspec(dllimport)
  37. #else /* ndef _DLL */
  38. #define _CRTIMP
  39. #endif /* _DLL */
  40. #endif /* _CRTIMP */
  41. /* Define __cdecl for non-Microsoft compilers */
  42. #if ( !defined(_MSC_VER) && !defined(__cdecl) )
  43. #define __cdecl
  44. #endif
  45. /* Definition of _exception struct - this struct is passed to the matherr
  46. * routine when a floating point exception is detected
  47. */
  48. #ifndef _EXCEPTION_DEFINED
  49. struct _exception {
  50. int type; /* exception type - see below */
  51. char *name; /* name of function where error occured */
  52. double arg1; /* first argument to function */
  53. double arg2; /* second argument (if any) to function */
  54. double retval; /* value to be returned by function */
  55. } ;
  56. #define _EXCEPTION_DEFINED
  57. #endif
  58. /* Definition of a _complex struct to be used by those who use cabs and
  59. * want type checking on their argument
  60. */
  61. #ifndef _COMPLEX_DEFINED
  62. struct _complex {
  63. double x,y; /* real and imaginary parts */
  64. } ;
  65. #if !__STDC__ && !defined (__cplusplus)
  66. /* Non-ANSI name for compatibility */
  67. #define complex _complex
  68. #endif
  69. #define _COMPLEX_DEFINED
  70. #endif
  71. #endif /* __assembler */
  72. /* Constant definitions for the exception type passed in the _exception struct
  73. */
  74. #define _DOMAIN 1 /* argument domain error */
  75. #define _SING 2 /* argument singularity */
  76. #define _OVERFLOW 3 /* overflow range error */
  77. #define _UNDERFLOW 4 /* underflow range error */
  78. #define _TLOSS 5 /* total loss of precision */
  79. #define _PLOSS 6 /* partial loss of precision */
  80. #define EDOM 33
  81. #define ERANGE 34
  82. /* Definitions of _HUGE and HUGE_VAL - respectively the XENIX and ANSI names
  83. * for a value returned in case of error by a number of the floating point
  84. * math routines
  85. */
  86. #ifndef __assembler /* Protect from assembler */
  87. _CRTIMP extern double _HUGE;
  88. #endif /* __assembler */
  89. #define HUGE_VAL _HUGE
  90. #ifdef _USE_MATH_DEFINES
  91. /* Define _USE_MATH_DEFINES before including math.h to expose these macro
  92. * definitions for common math constants. These are placed under an #ifdef
  93. * since these commonly-defined names are not part of the C/C++ standards.
  94. */
  95. /* Definitions of useful mathematical constants
  96. * M_E - e
  97. * M_LOG2E - log2(e)
  98. * M_LOG10E - log10(e)
  99. * M_LN2 - ln(2)
  100. * M_LN10 - ln(10)
  101. * M_PI - pi
  102. * M_PI_2 - pi/2
  103. * M_PI_4 - pi/4
  104. * M_1_PI - 1/pi
  105. * M_2_PI - 2/pi
  106. * M_2_SQRTPI - 2/sqrt(pi)
  107. * M_SQRT2 - sqrt(2)
  108. * M_SQRT1_2 - 1/sqrt(2)
  109. */
  110. #define M_E 2.71828182845904523536
  111. #define M_LOG2E 1.44269504088896340736
  112. #define M_LOG10E 0.434294481903251827651
  113. #define M_LN2 0.693147180559945309417
  114. #define M_LN10 2.30258509299404568402
  115. #define M_PI 3.14159265358979323846
  116. #define M_PI_2 1.57079632679489661923
  117. #define M_PI_4 0.785398163397448309616
  118. #define M_1_PI 0.318309886183790671538
  119. #define M_2_PI 0.636619772367581343076
  120. #define M_2_SQRTPI 1.12837916709551257390
  121. #define M_SQRT2 1.41421356237309504880
  122. #define M_SQRT1_2 0.707106781186547524401
  123. #endif /* _USE_MATH_DEFINES */
  124. /* Function prototypes */
  125. #if !defined(__assembler) /* Protect from assembler */
  126. int __cdecl abs(int);
  127. double __cdecl acos(double);
  128. double __cdecl asin(double);
  129. double __cdecl atan(double);
  130. double __cdecl atan2(double, double);
  131. double __cdecl cos(double);
  132. double __cdecl cosh(double);
  133. double __cdecl exp(double);
  134. double __cdecl fabs(double);
  135. double __cdecl fmod(double, double);
  136. long __cdecl labs(long);
  137. double __cdecl log(double);
  138. double __cdecl log10(double);
  139. double __cdecl pow(double, double);
  140. double __cdecl sin(double);
  141. double __cdecl sinh(double);
  142. double __cdecl tan(double);
  143. double __cdecl tanh(double);
  144. double __cdecl sqrt(double);
  145. _CRTIMP double __cdecl atof(const char *);
  146. _CRTIMP double __cdecl _cabs(struct _complex);
  147. _CRTIMP double __cdecl ceil(double);
  148. _CRTIMP double __cdecl floor(double);
  149. _CRTIMP double __cdecl frexp(double, int *);
  150. _CRTIMP double __cdecl _hypot(double, double);
  151. _CRTIMP double __cdecl _j0(double);
  152. _CRTIMP double __cdecl _j1(double);
  153. _CRTIMP double __cdecl _jn(int, double);
  154. _CRTIMP double __cdecl ldexp(double, int);
  155. int __cdecl _matherr(struct _exception *);
  156. _CRTIMP double __cdecl modf(double, double *);
  157. _CRTIMP double __cdecl _y0(double);
  158. _CRTIMP double __cdecl _y1(double);
  159. _CRTIMP double __cdecl _yn(int, double);
  160. #if defined(_M_IX86)
  161. _CRTIMP int __cdecl _set_SSE2_enable(int);
  162. #endif
  163. #if defined(_M_IA64)
  164. /* ANSI C, 4.5 Mathematics */
  165. /* 4.5.2 Trigonometric functions */
  166. float __cdecl acosf( float );
  167. float __cdecl asinf( float );
  168. float __cdecl atanf( float );
  169. float __cdecl atan2f( float , float );
  170. float __cdecl cosf( float );
  171. float __cdecl sinf( float );
  172. float __cdecl tanf( float );
  173. /* 4.5.3 Hyperbolic functions */
  174. float __cdecl coshf( float );
  175. float __cdecl sinhf( float );
  176. float __cdecl tanhf( float );
  177. /* 4.5.4 Exponential and logarithmic functions */
  178. float __cdecl expf( float );
  179. float __cdecl logf( float );
  180. float __cdecl log10f( float );
  181. float __cdecl modff( float , float* );
  182. /* 4.5.5 Power functions */
  183. float __cdecl powf( float , float );
  184. float __cdecl sqrtf( float );
  185. /* 4.5.6 Nearest integer, absolute value, and remainder functions */
  186. float __cdecl ceilf( float );
  187. float __cdecl fabsf( float );
  188. float __cdecl floorf( float );
  189. float __cdecl fmodf( float , float );
  190. float __cdecl hypotf(float, float);
  191. #endif /* _M_IA64 */
  192. /* Macros defining long double functions to be their double counterparts
  193. * (long double is synonymous with double in this implementation).
  194. */
  195. #ifndef __cplusplus
  196. #define acosl(x) ((long double)acos((double)(x)))
  197. #define asinl(x) ((long double)asin((double)(x)))
  198. #define atanl(x) ((long double)atan((double)(x)))
  199. #define atan2l(x,y) ((long double)atan2((double)(x), (double)(y)))
  200. #define _cabsl _cabs
  201. #define ceill(x) ((long double)ceil((double)(x)))
  202. #define cosl(x) ((long double)cos((double)(x)))
  203. #define coshl(x) ((long double)cosh((double)(x)))
  204. #define expl(x) ((long double)exp((double)(x)))
  205. #define fabsl(x) ((long double)fabs((double)(x)))
  206. #define floorl(x) ((long double)floor((double)(x)))
  207. #define fmodl(x,y) ((long double)fmod((double)(x), (double)(y)))
  208. #define frexpl(x,y) ((long double)frexp((double)(x), (y)))
  209. #define _hypotl(x,y) ((long double)_hypot((double)(x), (double)(y)))
  210. #define ldexpl(x,y) ((long double)ldexp((double)(x), (y)))
  211. #define logl(x) ((long double)log((double)(x)))
  212. #define log10l(x) ((long double)log10((double)(x)))
  213. #define _matherrl _matherr
  214. #define modfl(x,y) ((long double)modf((double)(x), (double *)(y)))
  215. #define powl(x,y) ((long double)pow((double)(x), (double)(y)))
  216. #define sinl(x) ((long double)sin((double)(x)))
  217. #define sinhl(x) ((long double)sinh((double)(x)))
  218. #define sqrtl(x) ((long double)sqrt((double)(x)))
  219. #define tanl(x) ((long double)tan((double)(x)))
  220. #define tanhl(x) ((long double)tanh((double)(x)))
  221. #else /* __cplusplus */
  222. inline long double acosl(long double _X)
  223. {return (acos((double)_X)); }
  224. inline long double asinl(long double _X)
  225. {return (asin((double)_X)); }
  226. inline long double atanl(long double _X)
  227. {return (atan((double)_X)); }
  228. inline long double atan2l(long double _X, long double _Y)
  229. {return (atan2((double)_X, (double)_Y)); }
  230. inline long double ceill(long double _X)
  231. {return (ceil((double)_X)); }
  232. inline long double cosl(long double _X)
  233. {return (cos((double)_X)); }
  234. inline long double coshl(long double _X)
  235. {return (cosh((double)_X)); }
  236. inline long double expl(long double _X)
  237. {return (exp((double)_X)); }
  238. inline long double fabsl(long double _X)
  239. {return (fabs((double)_X)); }
  240. inline long double floorl(long double _X)
  241. {return (floor((double)_X)); }
  242. inline long double fmodl(long double _X, long double _Y)
  243. {return (fmod((double)_X, (double)_Y)); }
  244. inline long double frexpl(long double _X, int *_Y)
  245. {return (frexp((double)_X, _Y)); }
  246. inline long double ldexpl(long double _X, int _Y)
  247. {return (ldexp((double)_X, _Y)); }
  248. inline long double logl(long double _X)
  249. {return (log((double)_X)); }
  250. inline long double log10l(long double _X)
  251. {return (log10((double)_X)); }
  252. inline long double modfl(long double _X, long double *_Y)
  253. {double _Di, _Df = modf((double)_X, &_Di);
  254. *_Y = (long double)_Di;
  255. return (_Df); }
  256. inline long double powl(long double _X, long double _Y)
  257. {return (pow((double)_X, (double)_Y)); }
  258. inline long double sinl(long double _X)
  259. {return (sin((double)_X)); }
  260. inline long double sinhl(long double _X)
  261. {return (sinh((double)_X)); }
  262. inline long double sqrtl(long double _X)
  263. {return (sqrt((double)_X)); }
  264. inline long double tanl(long double _X)
  265. {return (tan((double)_X)); }
  266. inline long double tanhl(long double _X)
  267. {return (tanh((double)_X)); }
  268. inline float frexpf(float _X, int *_Y)
  269. {return ((float)frexp((double)_X, _Y)); }
  270. inline float ldexpf(float _X, int _Y)
  271. {return ((float)ldexp((double)_X, _Y)); }
  272. #if !defined(_M_IA64)
  273. inline float acosf(float _X)
  274. {return ((float)acos((double)_X)); }
  275. inline float asinf(float _X)
  276. {return ((float)asin((double)_X)); }
  277. inline float atanf(float _X)
  278. {return ((float)atan((double)_X)); }
  279. inline float atan2f(float _X, float _Y)
  280. {return ((float)atan2((double)_X, (double)_Y)); }
  281. inline float ceilf(float _X)
  282. {return ((float)ceil((double)_X)); }
  283. inline float cosf(float _X)
  284. {return ((float)cos((double)_X)); }
  285. inline float coshf(float _X)
  286. {return ((float)cosh((double)_X)); }
  287. inline float expf(float _X)
  288. {return ((float)exp((double)_X)); }
  289. inline float fabsf(float _X)
  290. {return ((float)fabs((double)_X)); }
  291. inline float floorf(float _X)
  292. {return ((float)floor((double)_X)); }
  293. inline float fmodf(float _X, float _Y)
  294. {return ((float)fmod((double)_X, (double)_Y)); }
  295. inline float logf(float _X)
  296. {return ((float)log((double)_X)); }
  297. inline float log10f(float _X)
  298. {return ((float)log10((double)_X)); }
  299. inline float modff(float _X, float *_Y)
  300. { double _Di, _Df = modf((double)_X, &_Di);
  301. *_Y = (float)_Di;
  302. return ((float)_Df); }
  303. inline float powf(float _X, float _Y)
  304. {return ((float)pow((double)_X, (double)_Y)); }
  305. inline float sinf(float _X)
  306. {return ((float)sin((double)_X)); }
  307. inline float sinhf(float _X)
  308. {return ((float)sinh((double)_X)); }
  309. inline float sqrtf(float _X)
  310. {return ((float)sqrt((double)_X)); }
  311. inline float tanf(float _X)
  312. {return ((float)tan((double)_X)); }
  313. inline float tanhf(float _X)
  314. {return ((float)tanh((double)_X)); }
  315. #endif /* !defined(_M_IA64) */
  316. #endif /* __cplusplus */
  317. #endif /* __assembler */
  318. #if !__STDC__
  319. /* Non-ANSI names for compatibility */
  320. #define DOMAIN _DOMAIN
  321. #define SING _SING
  322. #define OVERFLOW _OVERFLOW
  323. #define UNDERFLOW _UNDERFLOW
  324. #define TLOSS _TLOSS
  325. #define PLOSS _PLOSS
  326. #define matherr _matherr
  327. #ifndef __assembler /* Protect from assembler */
  328. _CRTIMP extern double HUGE;
  329. _CRTIMP double __cdecl cabs(struct _complex);
  330. _CRTIMP double __cdecl hypot(double, double);
  331. _CRTIMP double __cdecl j0(double);
  332. _CRTIMP double __cdecl j1(double);
  333. _CRTIMP double __cdecl jn(int, double);
  334. int __cdecl matherr(struct _exception *);
  335. _CRTIMP double __cdecl y0(double);
  336. _CRTIMP double __cdecl y1(double);
  337. _CRTIMP double __cdecl yn(int, double);
  338. #endif /* __assembler */
  339. #endif /* __STDC__ */
  340. #ifdef __cplusplus
  341. }
  342. extern "C++" {
  343. template<class _Ty> inline
  344. _Ty _Pow_int(_Ty _X, int _Y)
  345. {unsigned int _N;
  346. if (_Y >= 0)
  347. _N = _Y;
  348. else
  349. _N = -_Y;
  350. for (_Ty _Z = _Ty(1); ; _X *= _X)
  351. {if ((_N & 1) != 0)
  352. _Z *= _X;
  353. if ((_N >>= 1) == 0)
  354. return (_Y < 0 ? _Ty(1) / _Z : _Z); }}
  355. #ifndef _MSC_EXTENSIONS
  356. inline long __cdecl abs(long _X)
  357. {return (labs(_X)); }
  358. inline double __cdecl abs(double _X)
  359. {return (fabs(_X)); }
  360. inline double __cdecl pow(double _X, int _Y)
  361. {return (_Pow_int(_X, _Y)); }
  362. inline double __cdecl pow(int _X, int _Y)
  363. {return (_Pow_int(_X, _Y)); }
  364. inline float __cdecl abs(float _X)
  365. {return (fabsf(_X)); }
  366. inline float __cdecl acos(float _X)
  367. {return (acosf(_X)); }
  368. inline float __cdecl asin(float _X)
  369. {return (asinf(_X)); }
  370. inline float __cdecl atan(float _X)
  371. {return (atanf(_X)); }
  372. inline float __cdecl atan2(float _Y, float _X)
  373. {return (atan2f(_Y, _X)); }
  374. inline float __cdecl ceil(float _X)
  375. {return (ceilf(_X)); }
  376. inline float __cdecl cos(float _X)
  377. {return (cosf(_X)); }
  378. inline float __cdecl cosh(float _X)
  379. {return (coshf(_X)); }
  380. inline float __cdecl exp(float _X)
  381. {return (expf(_X)); }
  382. inline float __cdecl fabs(float _X)
  383. {return (fabsf(_X)); }
  384. inline float __cdecl floor(float _X)
  385. {return (floorf(_X)); }
  386. inline float __cdecl fmod(float _X, float _Y)
  387. {return (fmodf(_X, _Y)); }
  388. inline float __cdecl frexp(float _X, int * _Y)
  389. {return (frexpf(_X, _Y)); }
  390. inline float __cdecl ldexp(float _X, int _Y)
  391. {return (ldexpf(_X, _Y)); }
  392. inline float __cdecl log(float _X)
  393. {return (logf(_X)); }
  394. inline float __cdecl log10(float _X)
  395. {return (log10f(_X)); }
  396. inline float __cdecl modf(float _X, float * _Y)
  397. {return (modff(_X, _Y)); }
  398. inline float __cdecl pow(float _X, float _Y)
  399. {return (powf(_X, _Y)); }
  400. inline float __cdecl pow(float _X, int _Y)
  401. {return (_Pow_int(_X, _Y)); }
  402. inline float __cdecl sin(float _X)
  403. {return (sinf(_X)); }
  404. inline float __cdecl sinh(float _X)
  405. {return (sinhf(_X)); }
  406. inline float __cdecl sqrt(float _X)
  407. {return (sqrtf(_X)); }
  408. inline float __cdecl tan(float _X)
  409. {return (tanf(_X)); }
  410. inline float __cdecl tanh(float _X)
  411. {return (tanhf(_X)); }
  412. inline long double __cdecl abs(long double _X)
  413. {return (fabsl(_X)); }
  414. inline long double __cdecl acos(long double _X)
  415. {return (acosl(_X)); }
  416. inline long double __cdecl asin(long double _X)
  417. {return (asinl(_X)); }
  418. inline long double __cdecl atan(long double _X)
  419. {return (atanl(_X)); }
  420. inline long double __cdecl atan2(long double _Y, long double _X)
  421. {return (atan2l(_Y, _X)); }
  422. inline long double __cdecl ceil(long double _X)
  423. {return (ceill(_X)); }
  424. inline long double __cdecl cos(long double _X)
  425. {return (cosl(_X)); }
  426. inline long double __cdecl cosh(long double _X)
  427. {return (coshl(_X)); }
  428. inline long double __cdecl exp(long double _X)
  429. {return (expl(_X)); }
  430. inline long double __cdecl fabs(long double _X)
  431. {return (fabsl(_X)); }
  432. inline long double __cdecl floor(long double _X)
  433. {return (floorl(_X)); }
  434. inline long double __cdecl fmod(long double _X, long double _Y)
  435. {return (fmodl(_X, _Y)); }
  436. inline long double __cdecl frexp(long double _X, int * _Y)
  437. {return (frexpl(_X, _Y)); }
  438. inline long double __cdecl ldexp(long double _X, int _Y)
  439. {return (ldexpl(_X, _Y)); }
  440. inline long double __cdecl log(long double _X)
  441. {return (logl(_X)); }
  442. inline long double __cdecl log10(long double _X)
  443. {return (log10l(_X)); }
  444. inline long double __cdecl modf(long double _X, long double * _Y)
  445. {return (modfl(_X, _Y)); }
  446. inline long double __cdecl pow(long double _X, long double _Y)
  447. {return (powl(_X, _Y)); }
  448. inline long double __cdecl pow(long double _X, int _Y)
  449. {return (_Pow_int(_X, _Y)); }
  450. inline long double __cdecl sin(long double _X)
  451. {return (sinl(_X)); }
  452. inline long double __cdecl sinh(long double _X)
  453. {return (sinhl(_X)); }
  454. inline long double __cdecl sqrt(long double _X)
  455. {return (sqrtl(_X)); }
  456. inline long double __cdecl tan(long double _X)
  457. {return (tanl(_X)); }
  458. inline long double __cdecl tanh(long double _X)
  459. {return (tanhl(_X)); }
  460. #endif /* _MSC_EXTENSIONS */
  461. }
  462. #endif /* __cplusplus */
  463. #ifdef _MSC_VER
  464. #pragma pack(pop)
  465. #endif /* _MSC_VER */
  466. #endif /* _INC_MATH */