PHP Math Functions

PHP Math Introduction

Math (Math) functions can handle values within the integer and float ranges.

Installation

Math (Math) functions are an integral part of PHP's core. These functions can be used without installation.

PHP Math Functions

PHP:Indicates the earliest PHP version that supports this function.

Function Description PHP
abs() Absolute value. 3
acos() Inverse cosine. 3
acosh() Inverse hyperbolic cosine. 4
asin() Inverse sine. 3
asinh() Inverse hyperbolic sine. 4
atan() Inverse tangent. 3
atan2() Inverse tangent of two parameters. 3
atanh() Inverse hyperbolic tangent. 4
base_convert() Convert numbers between any base. 3
bindec() Convert binary to decimal. 3
ceil() Round up to the nearest integer. 3
cos() Cosine. 3
cosh() Hyperbolic cosine. 4
decbin() Convert decimal to binary. 3
dechex() Convert decimal to hexadecimal. 3
decoct() Convert decimal to octal. 3
deg2rad() Convert degrees to radians. 3
exp() Return Ex value. 3
expm1() Return Ex The value of -1. 4
floor() Round down to the nearest integer. 3
fmod() Return the floating-point remainder of the division. 4
getrandmax() Display the maximum possible value of a random number. 3
hexdec() Convert hexadecimal to decimal. 3
hypot() Calculate the hypotenuse length of a right triangle. 4
is_finite() Determine if the value is finite. 4
is_infinite() Determine if the value is infinite. 4
is_nan() Determine if the value is a valid number. 4
lcg_value() Return a pseudo-random number in the range (0, 1). 4
log() Natural logarithm. 3
log10() Logarithm base 10. 3
log1p() Return log(1 + number). 4
max() Return the maximum value. 3
min() Return the minimum value. 3
mt_getrandmax() Display the maximum possible value of a random number. 3
mt_rand() Return a random integer using the Mersenne Twister algorithm. 3
mt_srand() Seed the Mersenne Twister random number generator. 3
octdec() Convert octal to decimal. 3
pi() Return the value of pi. 3
pow() Return x to the power of y. 3
rad2deg() Convert radians to degrees. 3
rand() Return a random integer. 3
round() Round the floating-point number. 3
sin() sine. 3
sinh() hyperbolic sine. 4
sqrt() square root. 3
srand() Seed the random number generator. 3
tan() tangent. 3
tanh() hyperbolic tangent. 4

PHP Math constants

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