php_math.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Jim Winstead <jimw@php.net> |
  14. | Stig Sæther Bakken <ssb@php.net> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef PHP_MATH_H
  18. #define PHP_MATH_H
  19. PHPAPI double _php_math_round(double value, int places, int mode);
  20. PHPAPI zend_string *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep);
  21. PHPAPI zend_string *_php_math_number_format_ex(double d, int dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len);
  22. PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base);
  23. PHPAPI zend_long _php_math_basetolong(zval *arg, int base);
  24. PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret);
  25. PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base);
  26. #include <math.h>
  27. #ifndef M_E
  28. #define M_E 2.7182818284590452354 /* e */
  29. #endif
  30. #ifndef M_LOG2E
  31. #define M_LOG2E 1.4426950408889634074 /* log_2 e */
  32. #endif
  33. #ifndef M_LOG10E
  34. #define M_LOG10E 0.43429448190325182765 /* log_10 e */
  35. #endif
  36. #ifndef M_LN2
  37. #define M_LN2 0.69314718055994530942 /* log_e 2 */
  38. #endif
  39. #ifndef M_LN10
  40. #define M_LN10 2.30258509299404568402 /* log_e 10 */
  41. #endif
  42. #ifndef M_PI
  43. #define M_PI 3.14159265358979323846 /* pi */
  44. #endif
  45. #ifndef M_PI_2
  46. #define M_PI_2 1.57079632679489661923 /* pi/2 */
  47. #endif
  48. #ifndef M_PI_4
  49. #define M_PI_4 0.78539816339744830962 /* pi/4 */
  50. #endif
  51. #ifndef M_1_PI
  52. #define M_1_PI 0.31830988618379067154 /* 1/pi */
  53. #endif
  54. #ifndef M_2_PI
  55. #define M_2_PI 0.63661977236758134308 /* 2/pi */
  56. #endif
  57. #ifndef M_SQRTPI
  58. #define M_SQRTPI 1.77245385090551602729 /* sqrt(pi) */
  59. #endif
  60. #ifndef M_2_SQRTPI
  61. #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */
  62. #endif
  63. #ifndef M_LNPI
  64. #define M_LNPI 1.14472988584940017414 /* ln(pi) */
  65. #endif
  66. #ifndef M_EULER
  67. #define M_EULER 0.57721566490153286061 /* Euler constant */
  68. #endif
  69. #ifndef M_SQRT2
  70. #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */
  71. #endif
  72. #ifndef M_SQRT1_2
  73. #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */
  74. #endif
  75. #ifndef M_SQRT3
  76. #define M_SQRT3 1.73205080756887729352 /* sqrt(3) */
  77. #endif
  78. /* Define rounding modes (all are round-to-nearest) */
  79. #ifndef PHP_ROUND_HALF_UP
  80. #define PHP_ROUND_HALF_UP 0x01 /* Arithmetic rounding, up == away from zero */
  81. #endif
  82. #ifndef PHP_ROUND_HALF_DOWN
  83. #define PHP_ROUND_HALF_DOWN 0x02 /* Down == towards zero */
  84. #endif
  85. #ifndef PHP_ROUND_HALF_EVEN
  86. #define PHP_ROUND_HALF_EVEN 0x03 /* Banker's rounding */
  87. #endif
  88. #ifndef PHP_ROUND_HALF_ODD
  89. #define PHP_ROUND_HALF_ODD 0x04
  90. #endif
  91. #endif /* PHP_MATH_H */