php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
php_math.h File Reference
#include <math.h>
#include "php_math_round_mode.h"

Go to the source code of this file.

Macros

#define M_E   2.7182818284590452354 /* e */
 
#define M_LOG2E   1.4426950408889634074 /* log_2 e */
 
#define M_LOG10E   0.43429448190325182765 /* log_10 e */
 
#define M_LN2   0.69314718055994530942 /* log_e 2 */
 
#define M_LN10   2.30258509299404568402 /* log_e 10 */
 
#define M_PI   3.14159265358979323846 /* pi */
 
#define M_PI_2   1.57079632679489661923 /* pi/2 */
 
#define M_PI_4   0.78539816339744830962 /* pi/4 */
 
#define M_1_PI   0.31830988618379067154 /* 1/pi */
 
#define M_2_PI   0.63661977236758134308 /* 2/pi */
 
#define M_SQRTPI   1.77245385090551602729 /* sqrt(pi) */
 
#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */
 
#define M_LNPI   1.14472988584940017414 /* ln(pi) */
 
#define M_EULER   0.57721566490153286061 /* Euler constant */
 
#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */
 
#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */
 
#define M_SQRT3   1.73205080756887729352 /* sqrt(3) */
 

Functions

PHPAPI double _php_math_round (double value, int places, int mode)
 
PHPAPI zend_string_php_math_number_format (double d, int dec, char dec_point, char thousand_sep)
 
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)
 
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)
 
PHPAPI zend_string_php_math_longtobase (zend_long arg, int base)
 
PHPAPI zend_long _php_math_basetolong (zval *arg, int base)
 
PHPAPI void _php_math_basetozval (zend_string *str, int base, zval *ret)
 
PHPAPI zend_string_php_math_zvaltobase (zval *arg, int base)
 

Macro Definition Documentation

◆ M_1_PI

#define M_1_PI   0.31830988618379067154 /* 1/pi */

Definition at line 66 of file php_math.h.

◆ M_2_PI

#define M_2_PI   0.63661977236758134308 /* 2/pi */

Definition at line 70 of file php_math.h.

◆ M_2_SQRTPI

#define M_2_SQRTPI   1.12837916709551257390 /* 2/sqrt(pi) */

Definition at line 78 of file php_math.h.

◆ M_E

#define M_E   2.7182818284590452354 /* e */

Definition at line 34 of file php_math.h.

◆ M_EULER

#define M_EULER   0.57721566490153286061 /* Euler constant */

Definition at line 86 of file php_math.h.

◆ M_LN10

#define M_LN10   2.30258509299404568402 /* log_e 10 */

Definition at line 50 of file php_math.h.

◆ M_LN2

#define M_LN2   0.69314718055994530942 /* log_e 2 */

Definition at line 46 of file php_math.h.

◆ M_LNPI

#define M_LNPI   1.14472988584940017414 /* ln(pi) */

Definition at line 82 of file php_math.h.

◆ M_LOG10E

#define M_LOG10E   0.43429448190325182765 /* log_10 e */

Definition at line 42 of file php_math.h.

◆ M_LOG2E

#define M_LOG2E   1.4426950408889634074 /* log_2 e */

Definition at line 38 of file php_math.h.

◆ M_PI

#define M_PI   3.14159265358979323846 /* pi */

Definition at line 54 of file php_math.h.

◆ M_PI_2

#define M_PI_2   1.57079632679489661923 /* pi/2 */

Definition at line 58 of file php_math.h.

◆ M_PI_4

#define M_PI_4   0.78539816339744830962 /* pi/4 */

Definition at line 62 of file php_math.h.

◆ M_SQRT1_2

#define M_SQRT1_2   0.70710678118654752440 /* 1/sqrt(2) */

Definition at line 94 of file php_math.h.

◆ M_SQRT2

#define M_SQRT2   1.41421356237309504880 /* sqrt(2) */

Definition at line 90 of file php_math.h.

◆ M_SQRT3

#define M_SQRT3   1.73205080756887729352 /* sqrt(3) */

Definition at line 98 of file php_math.h.

◆ M_SQRTPI

#define M_SQRTPI   1.77245385090551602729 /* sqrt(pi) */

Definition at line 74 of file php_math.h.

Function Documentation

◆ _php_math_basetolong()

PHPAPI zend_long _php_math_basetolong ( zval * arg,
int base )

Definition at line 752 of file math.c.

◆ _php_math_basetozval()

PHPAPI void _php_math_basetozval ( zend_string * str,
int base,
zval * ret )

Definition at line 796 of file math.c.

◆ _php_math_longtobase()

PHPAPI zend_string * _php_math_longtobase ( zend_long arg,
int base )

Definition at line 875 of file math.c.

◆ _php_math_number_format()

PHPAPI zend_string * _php_math_number_format ( double d,
int dec,
char dec_point,
char thousand_sep )

Definition at line 1098 of file math.c.

◆ _php_math_number_format_ex()

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 )

Definition at line 1103 of file math.c.

◆ _php_math_number_format_long()

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 )

Definition at line 1221 of file math.c.

◆ _php_math_round()

PHPAPI double _php_math_round ( double value,
int places,
int mode )

When extracting the integer part, the result may be incorrect as a decimal number due to floating point errors. e.g. 0.285 * 10000000000 => 2849999999.9999995 floor(0.285 * 10000000000) => 2849999999

Add 1 to the absolute value of the value adjusted by floor or ceil, use the exponent to return it to its original precision, and compare it with value. If it is equal to value, it is assumed that the absolute value is 1 smaller due to error and will be corrected. e.g. 0.285 * 10000000000 => 2849999999.9999995 floor(0.285 * 10000000000) => 2849999999 (tmp_value) tmp_value2 = 2849999999 + 1 => 2850000000 2850000000 / 10000000000 == 0.285 => true tmp_value = tmp_value2

Definition at line 167 of file math.c.

◆ _php_math_zvaltobase()

PHPAPI zend_string * _php_math_zvaltobase ( zval * arg,
int base )

Definition at line 941 of file math.c.