xref: /php-src/ext/standard/php_math.h (revision 94ddc74c)
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 
18 #ifndef PHP_MATH_H
19 #define PHP_MATH_H
20 
21 PHPAPI double _php_math_round(double value, int places, int mode);
22 PHPAPI zend_string *_php_math_number_format(double d, int dec, char dec_point, char thousand_sep);
23 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);
24 PHPAPI zend_string *_php_math_number_format_long(zend_long num, zend_long dec, const char *dec_point, size_t dec_point_len, const char *thousand_sep, size_t thousand_sep_len);
25 PHPAPI zend_string * _php_math_longtobase(zend_long arg, int base);
26 PHPAPI zend_long _php_math_basetolong(zval *arg, int base);
27 PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret);
28 PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base);
29 
30 #include <math.h>
31 
32 #ifndef M_E
33 #define M_E            2.7182818284590452354   /* e */
34 #endif
35 
36 #ifndef M_LOG2E
37 #define M_LOG2E        1.4426950408889634074   /* log_2 e */
38 #endif
39 
40 #ifndef M_LOG10E
41 #define M_LOG10E       0.43429448190325182765  /* log_10 e */
42 #endif
43 
44 #ifndef M_LN2
45 #define M_LN2          0.69314718055994530942  /* log_e 2 */
46 #endif
47 
48 #ifndef M_LN10
49 #define M_LN10         2.30258509299404568402  /* log_e 10 */
50 #endif
51 
52 #ifndef M_PI
53 #define M_PI           3.14159265358979323846  /* pi */
54 #endif
55 
56 #ifndef M_PI_2
57 #define M_PI_2         1.57079632679489661923  /* pi/2 */
58 #endif
59 
60 #ifndef M_PI_4
61 #define M_PI_4         0.78539816339744830962  /* pi/4 */
62 #endif
63 
64 #ifndef M_1_PI
65 #define M_1_PI         0.31830988618379067154  /* 1/pi */
66 #endif
67 
68 #ifndef M_2_PI
69 #define M_2_PI         0.63661977236758134308  /* 2/pi */
70 #endif
71 
72 #ifndef M_SQRTPI
73 #define M_SQRTPI       1.77245385090551602729  /* sqrt(pi) */
74 #endif
75 
76 #ifndef M_2_SQRTPI
77 #define M_2_SQRTPI     1.12837916709551257390  /* 2/sqrt(pi) */
78 #endif
79 
80 #ifndef M_LNPI
81 #define M_LNPI         1.14472988584940017414  /* ln(pi) */
82 #endif
83 
84 #ifndef M_EULER
85 #define M_EULER        0.57721566490153286061 /* Euler constant */
86 #endif
87 
88 #ifndef M_SQRT2
89 #define M_SQRT2        1.41421356237309504880  /* sqrt(2) */
90 #endif
91 
92 #ifndef M_SQRT1_2
93 #define M_SQRT1_2      0.70710678118654752440  /* 1/sqrt(2) */
94 #endif
95 
96 #ifndef M_SQRT3
97 #define M_SQRT3	       1.73205080756887729352  /* sqrt(3) */
98 #endif
99 
100 /* Define rounding modes (all are round-to-nearest) */
101 #ifndef PHP_ROUND_HALF_UP
102 #define PHP_ROUND_HALF_UP        0x01    /* Arithmetic rounding, up == away from zero */
103 #endif
104 
105 #ifndef PHP_ROUND_HALF_DOWN
106 #define PHP_ROUND_HALF_DOWN      0x02    /* Arithmetic rounding, down == towards zero */
107 #endif
108 
109 #ifndef PHP_ROUND_HALF_EVEN
110 #define PHP_ROUND_HALF_EVEN      0x03    /* Banker's rounding */
111 #endif
112 
113 #ifndef PHP_ROUND_HALF_ODD
114 #define PHP_ROUND_HALF_ODD       0x04
115 #endif
116 
117 #ifndef PHP_ROUND_CEILING
118 #define PHP_ROUND_CEILING        0x05
119 #endif
120 
121 #ifndef PHP_ROUND_FLOOR
122 #define PHP_ROUND_FLOOR          0x06
123 #endif
124 
125 #ifndef PHP_ROUND_TOWARD_ZERO
126 #define PHP_ROUND_TOWARD_ZERO    0x07
127 #endif
128 
129 #ifndef PHP_ROUND_AWAY_FROM_ZERO
130 #define PHP_ROUND_AWAY_FROM_ZERO 0x08
131 #endif
132 
133 #endif /* PHP_MATH_H */
134