HomeReferencePHPPHP 5 Math Functions

PHP 5 Math Functions

PHP Math Introduction

The math functions will handle values at intervals the vary of integer and float types.


The PHP maths functions are a part of the PHP core. No installation is needed to use these functions.

PHP 5 Math Functions

abs()Return the absolute (positive) value of a number
acos()Return the arc cosine of a number
acosh()Return the inverse hyperbolic cosine of a number
asin()Return the arc sine of a number
asinh()Return the inverse hyperbolic sine of a number
atan()Return the arc tangent of a number in radians
atan2()Return the arc tangent of two variables x and y
atanh()Return the inverse hyperbolic tangent of a number
base_convert()Convert a number from one number base to another
bindec()Convert a binary number to a decimal number
ceil()Round a number up to the nearest integer
cos()Return the cosine of a number
cosh()Return the hyperbolic cosine of a number
decbin()Convert a decimal number to a binary number
dechex()Convert a decimal number to a hexadecimal number
decoct()Convert a decimal number to an octal number
deg2rad()Convert a degree value to a radian value
exp()Calculate the exponent of e
expm1()Return exp(x) - 1
floor()Round a number down to the nearest integer
fmod()Return the remainder of x/y
getrandmax()Return the largest possible value returned by rand()
hexdec()Convert a hexadecimal number to a decimal number
hypot()Calculate the hypotenuse of a right-angle triangle
is_finite()Check whether a value is finite or not
is_infinite()Check whether a value is infinite or not
is_nan()Check whether a value is 'not-a-number'
lcg_value()Return a pseudo random number in a range between 0 and 1
log()Return the natural logarithm of a number
log10()Return the base-10 logarithm of a number
log1p()Return log(1+number)
max()Return the highest value in an array, or the highest value of several specified values
min()Return the lowest value in an array, or the lowest value of several specified values
mt_getrandmax()Return the largest possible value returned by mt_rand()
mt_rand()Generate a random integer using Mersenne Twister algorithm
mt_srand()Seed the Mersenne Twister random number generator
octdec()Convert an octal number to a decimal number
pi()Return the value of PI
pow()Return x raised to the power of y
rad2deg()Convert a radian value to a degree value
rand()Generate a random integer
round()Round a floating-point number
sin()Return the sine of a number
sinh()Return the hyperbolic sine of a number
sqrt()Return the square root of a number
srand()Seed the random number generator
tan()Return the tangent of a number
tanh()Return the hyperbolic tangent of a number

PHP 5 Predefined Math Constants

ConstantValueDescriptionPHP Version
INFINFThe infinitePHP 4
M_E2.7182818284590452354Return ePHP 4
M_EULER0.57721566490153286061Return Euler constantPHP 4
M_LNPI1.14472988584940017414Return the natural logarithm of PI: log_e(pi)PHP 5.2
M_LN20.69314718055994530942Return the natural logarithm of 2: log_e 2PHP 4
M_LN102.30258509299404568402Return the natural logarithm of 10: log_e 10PHP 4
M_LOG2E1.4426950408889634074Return the base-2 logarithm of E: log_2 ePHP 4
M_LOG10E0.43429448190325182765Return the base-10 logarithm of E: log_10 ePHP 4
M_PI3.14159265358979323846Return PiPHP 4
M_PI_21.57079632679489661923Return Pi/2PHP 4
M_PI_40.78539816339744830962Return Pi/4PHP 4
M_1_PI0.31830988618379067154Return 1/PiPHP 4
M_2_PI0.63661977236758134308Return 2/PiPHP 4
M_SQRTPI1.77245385090551602729Return the square root of PI: sqrt(pi)PHP 5.2
M_2_SQRTPI1.12837916709551257390Return 2/square root of PI: 2/sqrt(pi)PHP 4
M_SQRT1_20.70710678118654752440Return the square root of 1/2: 1/sqrt(2)PHP 4
M_SQRT21.41421356237309504880Return the square root of 2: sqrt(2)PHP 4
M_SQRT31.73205080756887729352Return the square root of 3: sqrt(3)PHP 5.2
PHP_ROUND_HALF_UP1Round halves upPHP 5.3
PHP_ROUND_HALF_DOWN2Round halves downPHP 5.3
PHP_ROUND_HALF_EVEN3Round halves to even numbersPHP 5.3
PHP_ROUND_HALF_ODD4Round halves to odd numbersPHP 5.3