The predefined math functions in PHP are used to handle the mathematical operations within the integer and float types. These math functions are part of the PHP core.
Installation: These functions have not required any installation. The complete list of PHP math functions are given below:
Example: Programs illustrate the decbin() function in PHP:
PHP
<?php echo decbin (12); ?> |
Output:
1100
The complete list of Math Functions are given below:
PHP math Function |
Description |
Example |
---|---|---|
abs() | Return the absolute (positive) value of a number. | |
acos() | Find the arc cosine of a number in radians. | |
acosh() | Find the inverse hyperbolic cosine of a number passed to it as an argument. | |
asin() | Find the arc sine of a number in radians. | |
asinh() | Find the inverse hyperbolic sine of a number passed to it as an argument. | |
atan2() | Calculate the arc tangent of two variables x and y passed to it as arguments. | |
atan() | Return tangent of an argument passed to it which has as a numeric value between -Pi/2 and Pi/2 radians. | |
atanh() | Return tangent of a number passed to it as an argument. | |
base_convert() | Convert a number given in an arbitrary base to a desired base. | |
bindec() | Return the decimal equivalent of the binary number | |
ceil() | This is used to round a number to the nearest greater integer. | |
cos() | Find the cosine of a number. | |
cosh() | Find the hyperbolic sine of an angle. | |
decbin() | Return a string containing a binary representation of the given decimal number argument. | |
dechex() | Convert a given decimal number to an equivalent hexadecimal number. | |
decoct() | Return the octal equivalent of a decimal number. | |
deg2rad() | Convert from degrees to radian, this is where the method deg2rad() comes in aid. | |
exp() | Calculate e raised to the power of the given argument. | |
expm1() | Calculate e raised to the power of the given argument minus one. | |
fmod() | Calculate the Modulo of any division | |
hexdec() | Converts a hexadecimal number to a decimal number | |
hypot() | Returns the square root of sum of the an square of arguments passed | |
intdiv() | Returns the integer quotient of the division of the given dividend and divisor. | |
is_finite() | Check whether a given input value is finite or not. | |
is_infinite() | Takes a single parameter which is a float that is to be checked. | |
is_nan() | Checks whether a value is ‘not a number’. | |
log10() | Calculates the base 10 logarithm of a number | |
log() | Calculates the base 10 logarithms of a number | |
max() | Return the maximum value in an array. | |
min() | Return the lowest value in an array. | |
mt_rand() | Generates a random integer between the specified minimum and maximum values | |
octdec() | Calculate the decimal equivalent of an octal number. | |
pi() | Return the value of π. | |
pow() | It is used with a number raised to any value. | |
rad2deg() | Represents an angle in Radians. | |
rand() | Generate a random integer. | |
round( | Round a floating-point number | |
sin() | Find the sine value of a number. | |
sinh() | Find the hyperbolic sine of an angle. | |
sqrt() | Calculate the square root of a number. | |
srand() | Seed the random number generator rand(). | |
tan() | Find the tangent of the argument parameter. | |
tanh() | Find the hyperbolic tangent of an angle passed to it as a parameter. |