Math functions can handle values in the integer and float ranges.
The PHP Math function is an integral part of PHP core. No installation is required to use these functions.
| function | describe |
|---|---|
| abs() | 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 arctangent of a number. |
| atan2() | Returns the arc tangent of two variables x and y. |
| atanh() | Returns the inverse hyperbolic tangent of a number. |
| base_convert() | Convert numbers between arbitrary bases. |
| bind() | Convert binary number to decimal number. |
| ceil() | 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 Ex. |
| expm1() | Returns the value of Ex-1. |
| floor() | Round down to the nearest integer. |
| fmod() | Returns the floating point remainder of x/y. |
| getrandmax() | Returns the largest 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. |
| 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 (base E) of a number. |
| 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 largest 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() | Seeding 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 y power. |
| rad2deg() | Convert radian values to angle values. |
| rand() | Returns a random integer. |
| round() | Round 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. |
| constant | value | describe | PHP version |
|---|---|---|---|
| INF | INF | unlimited | PHP 4 |
| M_E | 2.7182818284590452354 | returne | PHP 4 |
| M_EULER | 0.57721566490153286061 | Return Euler constant | PHP 4 |
| M_LNPI | 1.14472988584940017414 | Returns the natural logarithm of PI: log_e(pi) | PHP 5.2 |
| M_LN2 | 0.69314718055994530942 | Returns the natural logarithm of 2: log_e 2 | PHP 4 |
| M_LN10 | 2.30258509299404568402 | Returns the natural logarithm of 10: log_e 10 | PHP 4 |
| M_LOG2E | 1.4426950408889634074 | Returns the base 2 logarithm of E: log_2 e | PHP 4 |
| M_LOG10E | 0.43429448190325182765 | Returns the base 10 logarithm of E: log_10 e | PHP 4 |
| M_PI | 3.14159265358979323846 | Return Pi | PHP 4 |
| M_PI_2 | 1.57079632679489661923 | ReturnPi/2 | PHP 4 |
| M_PI_4 | 0.78539816339744830962 | Return Pi/4 | PHP 4 |
| M_1_PI | 0.31830988618379067154 | Return 1/Pi | PHP 4 |
| M_2_PI | 0.63661977236758134308 | Return 2/Pi | PHP 4 |
| M_SQRTPI | 1.77245385090551602729 | Returns the square root of pi: sqrt(pi) | PHP 5.2 |
| M_2_SQRTPI | 1.12837916709551257390 | Returns 2/square root of PI: 2/sqrt(pi) | PHP 4 |
| M_SQRT1_2 | 0.70710678118654752440 | Returns the square root of 1/2: 1/sqrt(2) | PHP 4 |
| M_SQRT2 | 1.41421356237309504880 | Returns the square root of 2: sqrt(2) | PHP 4 |
| M_SQRT3 | 1.73205080756887729352 | Returns the square root of 3: sqrt(3) | PHP 5.2 |
| NAN | NAN | not a number | PHP 4 |
| PHP_ROUND_HALF_UP | 1 | Round up when encountering .5 | PHP 5.3 |
| PHP_ROUND_HALF_DOWN | 2 | Round down when encountering .5 | PHP 5.3 |
| PHP_ROUND_HALF_EVEN | 3 | When encountering .5, round to an even number. | PHP 5.3 |
| PHP_ROUND_HALF_ODD | 4 | When encountering .5, round to an odd number. | PHP 5.3 |