Summary of common mathematical functions in PHP, summary of mathematical functions
This paper summarizes and analyzes the common mathematical functions of PHP. Share to everyone for your reference. The specific analysis is as follows:
ABS () function definition and usage: Returns the absolute value of a number.
Syntax: ABS (x), the code is as follows:
Copy the Code code as follows: $abs =abs (-3.2); $abs =3.2
$abs 2=abs (5); $abs 2=5
$abs 3=abs (-5); $abs 3=5
Ceil () function definition and usage: rounded up to the nearest integer.
Syntax Ceil (x)
Parameters |
Describe |
X |
Required, one number. |
Note: Returns the next integer not less than x, X if there is a fractional part, the type returned by Ceil () is still float, because the range of float values is usually larger than the integer, and the instance code is as follows:
Copy the Code code as follows: Echo Ceil (5); 5
echo "
";
echo ceil (3.3); 4
echo "
";
echo ceil (6.999); 7
The floor () function rounds down to the nearest integer.
Syntax: Floor (x)
Parameters |
Describe |
X |
Required, one number. |
Description: Returns the next integer not less than x, rounding out the fractional part of X, and the type of floor () returned is still float, because the range of float values is usually larger than the integer.
Copy the Code code as follows: Echo floor (4); 4
echo "
";
echo Floor (3.3); 3
echo "
";
echo Floor (6.999); 6
Definition and usage
The Fmod () function returns the remainder of the floating-point number of divisions.
Syntax: Fmod (x, y)
Parameters |
Describe |
X |
Required, one number. |
Y |
Required, one number. |
Note: Returns the remainder of the floating-point number divided by the divisor (x) by the divisor (y), where the remainder (r) is defined as: x = i * y + R, where I is an integer and if Y is a non-0 value, then r and X are the same symbol and their quantity value is less than Y, the code is:
Copy the Code code as follows: $x = 4.7; Defining the value 1
$y = 1.3; Defining the Value 2
$r =fmod ($x, $y); Perform redundancy operations
echo $x. " Divided by ". $y." The remainder of the floating-point number is: ". $r; Output results
LOG10 () The logarithm of the base 10.
Syntax: log10 (x)
Parameters |
Describe |
X |
Required, one number. |
Description: Returns the base 10 logarithm of the parameter x, with the following code:
Copy the Code code as follows: $num 1=100;
$num 2=1000;
$num 3=3;
$result 1=log10 ($num 1);
$result 2=log10 ($num 2);
$result 3=log10 ($num 3);
echo "$num 1 with a base of 10 logarithm for $result1";
echo "
";
echo "$num 2 with a base of 10 logarithm for $result2";
echo "
";
echo "$num 3 with a base of 10 logarithm for $RESULT3";
echo "
";
Log () returns the natural logarithm.
Syntax: Log (x,base)
Parameters |
Describe |
X |
Required, one number. |
Base is optional and returns Logbasex if the parameter is specified.
Note: If an optional parameter Base,log () is specified to return logbasex, log () returns the natural logarithm of the parameter x, which is the following example code:
Copy the Code code as follows: Echo log (2.7183); Returns the natural logarithm of a specified number
echo "
";
echo log (2); Returns the natural logarithm of a specified number
echo "
";
echo log (1); Returns the natural logarithm of a specified number
echo "
";
echo log (0); Returns the natural logarithm of a specified number
echo "
";
Echo log (-1); Returns the natural logarithm of a specified number
//
echo sqrt (9); Output 3
echo "
";
echo sqrt (10); 3.16227766 ...
//
Var_dump (POW (2, 8)); Output 256
echo "
";
Echo Pow ( -1,20); Output 1
echo "
";
Echo Pow (0,0); Output 1
echo "
";
Echo Pow (-1, 4.5); return error
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/915430.html www.bkjia.com true http://www.bkjia.com/PHPjc/915430.html techarticle PHP Common Mathematical function Summary, mathematical function Summary This article summarizes and analyzes the common mathematical functions of PHP. Share to everyone for your reference. The specific analysis is as follows: ABS () function definition and usage ...