PHP Math functions

Quick reference to the math functions of PHP.

Math functions
Function Returns Does what
abs(x) Mixed Returns absolute value of "x"
ceil(x) Float Rounds up to next integer
floor(x) Float Rounds down to next integer
round(x [, precision [, mode]]) Float Returns "x" rounded to nearest integer
exp(x) Float Returns E to the power of "x"
exp1(x) Float Returns exp(x)-1 for close-to-zero "x"
fmod(x, y) Float Returns floating-point modulo of (x/y)
intdiv(x, y) Integer Returns integer-part of result of (x/y)
is_finite(x) Boolean Returns true if "x" is finite number
is_infinite(x) Boolean Returns true if "x" is infinite number, or larger than system Float limits
is_nan(x) Boolean Returns true if "x" is not a number
log(x [, base]) Float Returns natural logarithm, or "base" logarithm
log10(x) Float Returns base 10 logarithm of "x"
log1p(x) Float Returns log(1+x) for close-to-zero "x"
max(x, y [, ...]) Mixed Returns the highest value
min(x, y [, ...]) Mixed Returns the lowest value
number_format(x, decimals, dec_point, 1000sep) String Returns "x" formatted
pi() Float Returns value of pi (π)
pow(x, y) Float Returns "x" to the power of "y"
sqrt(x) Float Returns square root of "x"
Trigonometry
Function Returns Does what
cos(x) Float Returns cosine of "x" in radians
sin(x) Float Returns sine of "x" in radians
tan(x) Float Returns tangent of "x" in radians
acos(x) Float Returns arc cosine of "x" in radians
acosh(x) Float Returns inverse hyperbolic cosine of "x"
asin(x) Float Returns arc sine of "x" in radians
asinh(x) Float Returns inverse hyperbolic sine of "x"
atan(x) Float Returns arc tangent of "x" in radians
atanh(x) Float Returns inverse hyperbolic tangent of "x"
atan2(x, y) Float Returns arc tangent of "x" and "y"
hypot(x, y) Float Returns hypotenuse of right-angle triangle (√(x² + y²))
Conversion
Function Returns Does what
base_convert(x, from_base, to_base) String Converts "x" from "from_base" to "to_base"
bindec(x) Float Converts "x" from binary to decimal
decbin(x) String Converts "x" from decimal to binary
dechex(x) String Converts "x" from decimal to hexadecimal
decoct(x) String Converts "x" from decimal to octal
deg2rad(x) Float Converts "x" from degrees to radians
hexdec(x) Integer Converts "x" from hexadecimal to decimal
octdec(x) Integer Converts "x" from octal to decimal
rad2deg(x) Float Converts "x" from radians to degrees
Random numbers
Function Returns Does what
rand([min , max]) Integer Returns pseudo random value ("min"-"max")
mt_rand(min, max) Integer Returns Mersenne Twister random value ("min"-"max")
lcg_value() Float Returns pseudo-random number between 0-1
random_int(min, max) Integer Returns cryptographically secure pseudo-random integer
getrandmax() Integer Returns greatest rand() value
mt_getrandmax() Integer Returns greatest mt_rand() value
srand(integer) Nothing Seeds the rand() PRNG
mt_srand([integer]) Nothing Seeds the Mersenne Twister PRNG

More: