PHP Math



PHP Math Introduction

The Math function can handle values ​​in the integer and float ranges.


Installation

PHP Math function is an integral part of the PHP core. No installation is required to use these functions.


PHP 5 Math function

Returns the absolute value of a number. acos()Returns the arc cosine of a number. acosh()Returns the inverse hyperbolic cosine of a number. asin()Returns the arcsine of a number. asinh()Returns the inverse hyperbolic sine of a number. atan()Returns the arc tangent of a number. atan2()Returns the arctangent of two variables x and y. atanh()Returns the inverse hyperbolic tangent of a number. base_convert()Convert numbers between arbitrary bases. bindec()Convert binary number to decimal number. Round up to the nearest integer. cos()Returns the cosine of a number. cosh()Returns the hyperbolic cosine of a number. decbin()Convert decimal number to binary number. dechex()Convert decimal number to hexadecimal number. decoct()Convert decimal number to octal number. deg2rad()Convert angle values ​​to radians. exp() Returns the value of Eexpm1()Returns the value of ERound down to the nearest integer. Returns the floating point remainder of x/y. getrandmax()Returns the maximum possible value of the random number displayed by calling the rand() function. hexdec()Convert hexadecimal number to decimal number. hypot()Calculate the length of the hypotenuse of a right triangle. is_finite() Determine whether it is a finite value. is_infinite() Determine whether it is an infinite value.
FunctionDescription
##abs( )
ceil()
x.
x - 1.
floor()
fmod()
is_nan() Determine whether it is a non-numeric value.
lcg_value()Returns a pseudo-random number in the range (0, 1).
#log()Returns the natural logarithm of a number (base E).
log10()Returns the base 10 logarithm of a number.
log1p()Return log(1+number)
max()Returns the maximum value in an array, or the maximum value among several specified values.
min()Returns the minimum value in an array, or the minimum value among several specified values.
mt_getrandmax()Returns the maximum possible value of the random number displayed by calling the mt_rand() function.
mt_rand()Generate random integers using the Mersenne Twister algorithm.
mt_srand()Seed the Mersenne Twister random number generator.
octdec()Convert octal number to decimal number.
pi()Returns the value of pi.
pow()Returns x raised to the yth power.
rad2deg()Convert radian value to angle value.
rand()Returns a random integer.
round() Rounds floating point numbers.
sin()Returns the sine of a number.
sinh()Returns the hyperbolic sine of a number.
sqrt()Returns the square root of a number.
srand() Seeding a random number generator.
tan()Returns the tangent of a number.
tanh()Returns the hyperbolic tangent of a number.


PHP 5 predefined Math constants

##1.57079632679489661923Return to Pi/ 2PHP 4M_PI_40.78539816339744830962Return to Pi/4PHP 4M_1_PI0.31830988618379067154Return 1/PiPHP 4M_2_PI0.63661977236758134308Return 2/PiPHP 4M_SQRTPI1.77245385090551602729Return The square root of PI: sqrt(pi)PHP 5.2M_2_SQRTPI1.12837916709551257390Returns 2/square root of PI :2/sqrt(pi)PHP 4M_SQRT1_20.70710678118654752440Returns the square root of 1/2: 1/ sqrt(2)PHP 4M_SQRT21.41421356237309504880Returns the square root of 2: sqrt(2)PHP 4M_SQRT31.73205080756887729352Returns the square root of 3: sqrt(3)PHP 5.2NANNAN is not a numberPHP 4PHP_ROUND_HALF_UP1Round up when encountering .5PHP 5.3##PHP_ROUND_HALF_DOWN##PHP_ROUND_HALF_EVEN3 When encountering .5, round to an even numberPHP 5.3PHP_ROUND_HALF_ODD4When encountering .5 In case of odd number roundingPHP 5.3
ConstantValueDescriptionPHP Version
INFINFUnlimitedPHP 4
M_E2.7182818284590452354Return ePHP 4
M_EULER0.57721566490153286061 Return Euler constantPHP 4
M_LNPI1.14472988584940017414Return the natural logarithm of pi: log_e(pi)PHP 5.2
M_LN20.69314718055994530942Returns the natural logarithm of 2: log_e 2PHP 4
M_LN102.30258509299404568402 Returns the natural logarithm of 10: log_e 10PHP 4
M_LOG2E1.4426950408889634074Returns the base 2 logarithm of E: log_2 e#PHP 4
M_LOG10E0.43429448190325182765Returns the base 10 logarithm of E: log_10 ePHP 4
M_PI3.14159265358979323846Return to PiPHP 4
M_PI_2
2Round down when encountering .5PHP 5.3