This paper summarizes and analyzes the PHP mathematical operation function. Share to everyone for your reference, specific as follows:
First, the commonly used function description:
Abs: Get absolute value.
Acos: Gets the inverse cosine value.
Asin: Get the inverse chord value.
Atan: Get the tangent value.
Atan2: Calculates the inverse tangent value of two numbers.
Base_convert: Converts the rounding of a number.
Bindec: The binary turns into 10 carry.
Ceil: Calculates the smallest integer greater than the specified number.
COS: cosine calculation.
Decbin: Decimal Turn binary.
Dechex: Decimal Turn 16 carry.
DECOCT: Decimal turn octal.
EXP: The secondary value of the natural logarithm E.
Floor: Calculates the largest integer less than the specified number.
Getrandmax: The maximum value of random numbers.
Hexdec: 16 Carry turn decimal.
Log: Natural to numeric values.
The log10:10 value of the substrate.
Max: Gets the maximum value.
Min: Get the minimum value.
Mt_rand: Get the random value.
Mt_srand: Configure random number of seeds.
Mt_getrandmax: The maximum value of random numbers.
Number_format: Formats the numeric string.
Octdec: Octal turn decimal.
Pi: Pi.
POW: the second side.
Rand: Get a random number.
Round: Rounded.
Sin: sine calculation.
Sqrt: Open square root.
Srand: Configure random number of seeds.
Tan: Tangent calculation.
Second, the function analysis is as follows:
Abs
Get absolute value.
Syntax: Mixed ABS (mixed number);
Return value: Mixed type data
Types of functions: mathematical operations
Content Description: Returns the absolute value of the parameter number. If number is an exact floating-point number, the return value is also a floating-point number, and the other type returns the type as an integer.
Acos
Gets the inverse cosine value.
Syntax: float acos (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: Returns the inverse cosine value (arc cosine) of the parameter arg.
Reference: ASIN () Atan ()
Asin
Get the string value anyway.
Syntax: Float ASIN (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Content Description: Returns the inverse chord value (arc sine) of the parameter arg.
Reference: ACOs () Atan ()
Atan
Gets the inverse tangent value.
Syntax: float atan (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Content Description: Returns the tangent value (arc tangent) of the argument Arg.
Reference: ACOs () ASIN ()
Atan2
Calculates the tangent value of a two number.
Syntax: float atan2 (float y, float x);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function is used to calculate the two-number y, X of the inverse tangent value, calculated and Atan () calculated y/x similar, but this function will be x, y of the positive and negative effects of the result. The return value of this function must fall between positive and negative pi (-pi <= (value) ≶= pi)
Reference ACOs () Atan () ASIN ()
Base_convert
converts the rounding of a number.
Syntax: string Base_convert (string number, int frombase, int tobase);
return value: String
Types of functions: mathematical operations
Description: This function converts numeric string number from Frombase to tobase rounding. The way that this type can be handled by a binary to a 36-digit rounding. Before the decimal, it is expressed in numbers, and after the decimal, it is expressed in English letters. For example, the order of 16 decimal digits in sequence is the 17th, in which case the 123456789abcdef,10 is entered in one place. And 36 carry A is tenth, B is 11th, Z is 36th, 10 is 37th, then carry.
Usage examples
This example turns a 16-digit string into a binary string
<?php
$binary = Base_convert ($hexadecimal, 2);
The echo "16-carry string" $hexadecimal "is converted to binary as" $binary ". ";
? >
Bindec
The binary turns into 10 carry.
Syntax: int bindec (string binary_string);
return value: Integer
Types of functions: mathematical operations
Description: This function converts a binary numeric string to a 10-digit integer. Because PHP uses a 32-bit signed integer calculation, the maximum number of decimal digits that can be processed is 2147483647, which is 1111111111111111111111111111111 (31 1) of the binary number.
Reference: Decbin ()
Ceil
Calculates the smallest integer greater than the specified number.
Syntax: int ceil (float number);
return value: Integer
Types of functions: mathematical operations
Description: This function is used to calculate the smallest integer number larger than the floating-point parameter.
Usage examples
This example returns a value of 4.
<?php
$nextint =ceil (3.14);
echo $nextint;
? >
Reference: Floor () round ()
Cos
Cosine calculation.
Syntax: float cos (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the cosine of the parameter arg (cosine).
Reference: Sin () Tan ()
Decbin
Decimal turn binary.
Syntax: string decbin (int number);
return value: String
Types of functions: mathematical operations
Description: This function turns the decimal number into a binary string. Because PHP uses a 32-bit signed integer calculation, the maximum number of decimal digits that can be processed is 2147483647, which is 1111111111111111111111111111111 (31 1) of the binary number.
Reference: Bindec ()
Dechex
The decimal turns 16 carry.
Syntax: string dechex (int number);
return value: String
Types of functions: mathematical operations
Description: This function converts the decimal number to a 16-digit string. Because PHP uses a 32-bit signed integer calculation, the maximum number of decimal digits that can be processed is 2147483647, which is the 16-digit 7fffffff.
Reference: Hexdec ()
Decoct
Decimal to octal.
Syntax: string decoct (int number);
return value: String
Types of functions: mathematical operations
Description: This function converts the decimal number to an octet string. Because PHP uses a 32-bit signed integer calculation, the maximum number of decimal digits that can be processed is 2147483647, which is the octet number 17777777777.
Reference: Octdec ()
Exp
The secondary value of the natural logarithm E.
Syntax: float exp (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the arg natural value of the natural logarithm (logarithm).
Reference: POW () Log ()
Floor
Calculates the largest integer less than the specified number.
Syntax: int floor (float number);
return value: Integer
Types of functions: mathematical operations
Description: This function is used to calculate the largest integer smaller than the number of floating-point arguments.
Usage examples
This example returns a value of 3.
<?php
$lastint =floor (3.14);
echo $lastint;
? >
Reference: Ceil () round ()
Getrandmax
The maximum number of chaotic numbers.
Syntax: int getrandmax (void);
return value: Integer
Types of functions: mathematical operations
Description: This function calculates the maximum number of chaotic values that rand () may obtain. This function does not require arguments.
Reference: Rand () Srand () Mt_rand () Mt_srand () Mt_getrandmax ()
Hexdec
The 16 carry turns to the decimal.
Syntax: int hexdec (string hex_string);
return value: Integer
Types of functions: mathematical operations
Description: This function turns the 16-digit string into a 10-decimal number. Because PHP uses a 32-bit signed integer, the maximum 16 digits that can be processed are 7FFFFFFF, which is 2147483647 of the decimal digit.
Reference: Dechex ()
Log
Natural to numeric values.
Syntax: float log (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the natural logarithm (natural logarithm) value of the parameter arg.
Log10
10 the value of the base.
Syntax: float log10 (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the 10 base pair value of the parameter arg.
Max
Gets the maximum value.
Syntax: Mixed max (mixed arg1, mixed arg2 ... mixed argn);
Return value: Mixed type data
Types of functions: mathematical operations
Content Description: This function calculates the maximum value between parameters. If the first argument is a numeric array, the maximum number of that array is found. If the first argument is not an array, then more than two arguments are required. These numbers can be integers, multiples of exact numbers, or types of numeric strings. The number of parameters is not limited, depending on the user's needs. In the calculation, as long as there is only one argument is the exact number of times, this function will be all parameters to multiply the exact number, and return the exact number of times. If the argument has only an integer and a numeric string, all arguments are converted to integers and integers are returned.
Reference: Min ()
Min
Gets the minimum value.
Syntax: mixed min (mixed arg1, mixed arg2 ... mixed argn);
Return value: Mixed type data
Types of functions: mathematical operations
Content Description: This function calculates the minimum value between parameters. If the first argument is a numeric array, the smallest number of the array is found. If the first argument is not an array, then more than two arguments are required. These numbers can be integers, multiples of exact numbers, or types of numeric strings. The number of parameters is not limited, depending on the user's needs. In the calculation, as long as there is only one argument is the exact number of times, this function will be all parameters to multiply the exact number, and return the exact number of times. If the argument has only an integer and a numeric string, all arguments are converted to integers and integers are returned.
Reference: Max ()
Mt_rand
get the number of chaos.
Syntax: int mt_rand ([int min], [int Max]);
return value: Integer
Types of functions: mathematical operations
Content Description: This function does not use the commonly used LIBC to compute the chaos value, but uses the horse's Dorset rotation (Mersenne twister) algorithm which calculates the speed to be at least fast four times times to compute the chaotic numerical value. The http://www.math.keio.ac.jp/~matumoto/emt.html rotation algorithm can find more relevant information in the Matsumoto true, and the optimized original program is HTTP://WWW.SCP.SYR.EDU/~MARC /hawk/twister.html. If you do not specify the maximum and minimum range of chaotic numbers, this function automatically takes a random number from 0 to Rand_max. If you specify min and Max parameters, a number from the specified parameters, such as Mt_rand (38, 49), will be taken from 38 to 49 for an scrambling value. It is noteworthy that in order to maximize the chaos of chaos, it is best to use Mt_srand () to configure new random seeds each time before scrambling numbers are taken.
Reference: Rand () Srand () Getrandmax () Mt_srand () Mt_getrandmax ()
Mt_srand
Configure the number of random seeds.
Syntax: void mt_srand (int seed);
return value: None
Types of functions: mathematical operations
Description: After the function passed the parameter seed, configure the seed of the chaos number. It is worth noting that the parameter seed value is best also a random number, such as the use of time as a variable to the source is a good way, or to develop other hardware peripheral interface to achieve better chaos number.
Usage examples
This example adds a time factor to the execution of one out of 10,000 seconds when the number of seeds is scrambled
<?php
Mt_srand (double) microtime () *1000000);
$randval = Mt_rand ();
echo $randval;
? >
Reference: Rand () Srand () Getrandmax () Mt_rand () Mt_getrandmax ()
Mt_getrandmax
the maximum number of chaotic numbers.
Syntax: int mt_getrandmax (void);
return value: Integer
Types of functions: mathematical operations
Description: This function calculates the maximum amount of chaos that can be obtained by the Mt_rand () of the chaotic number function. This function does not require arguments.
Reference: Rand () Srand () Getrandmax () Mt_srand () Mt_rand ()
Number_format
formats a numeric string.
Syntax: string Number_format (float number, int [decimals], string [Dec_point], string [thousands_sep]);
return value: String
Types of functions: mathematical operations
Description: This function is used to format floating-point parameter number. If no parameter is decimals, the returned string is returned as long as the integer part is added to the number of decimal digits specified by the parameter. The parameter dec_point represents the way the decimal point is represented, and the default value is ".", which can be changed in this argument if it needs to be converted to another decimal point. The parameter thousands_sep is a three-bit delimited symbol for the integer part, and the default value is ",". The most special place in this function is the number of parameters, at least one, the string to be formatted, or two or four parameters, but not three parameters. It is noteworthy that the number of digits after the specified decimal point is discarded directly, without rounding.
Usage examples
<?php
$short _pi = "3.14159";
$my _pi = Number_format ($short _pi, 2);
echo $my _pi. " n "; 3.14
$foo = 850017.9021;
$new _foo = Number_format ($foo, 3, ".", "");
echo $new _foo. " n "; 850 017.902
?>
Octdec
The octal turns to the decimal.
Syntax: string decoct (int number);
return value: String
Types of functions: mathematical operations
Description: This function turns the octal string into a 10-digit number. Because PHP uses a 32-bit signed integer calculation, it can handle the largest octet number of 17777777777, which is 2147483647 of the decimal digit.
Reference: Decoct ()
Pi
Pi.
Syntax: Double pi (void);
Return value: times the exact number
Types of functions: mathematical operations
Content Description: This function returns PI. No input parameters are required.
Pow
the second party.
Syntax: Float POW (float base, float exp);
Return values: Floating point numbers
Types of functions: mathematical operations
Content Description: This function calculates the secondary value. The parameter base is base and exp is a power number.
Usage examples
<?php
Print (POW (2,3));//8
print (POW (5,4));//625
?>
Reference: Log10 () Exp ()
Rand
Gets the random value.
Syntax: int rand ([int min], [int Max]);
return value: Integer
Types of functions: mathematical operations
Description: This function is used to obtain a random value. Without specifying the maximum and minimum range of random numbers, this function automatically takes a random number from 0 to Rand_max. If a parameter is specified for min and Max, a number is taken from the specified parameter. For example, Rand (38, 49) takes a random number from 38 to 49, and the UNIX system contains 49, and the WIN32 system does not contain an ([Email=zkimmel@earthlink.net]zkimmel@earthlink.net[/ema IL] 10-may-1999). It is noteworthy that in order to maximize the chaos of random numbers, it is best to use Srand () to configure a new random number seed each time before taking a random number.
Reference: Srand () Getrandmax () Mt_rand () Mt_srand () Mt_getrandmax ()
Round
Rounded.
Syntax: Double round (double val);
Return value: times the exact number
Types of functions: mathematical operations
Description: This function is used to round the number of decimal points.
Usage examples
<?php
$foo 1 = round (3.4);
$foo 2 = round (3.5);
$foo 3 = round (3.6);
echo "Round (3.4):". $foo 1. " <br>n ";
echo "Round (3.5):". $foo 2. " <br>n ";
echo "Round (3.6):". $foo 3;
? >
Reference: Ceil () Floor ()
Sin
sine calculation.
Syntax: float sin (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the sine value of the parameter arg (sine).
Reference: Cos () Tan ()
Sqrt
Open the square root.
Syntax: float sqrt (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function opens the square root of argument Arg.
Srand
Configure random number of seeds.
Syntax: void srand (int seed);
return value: None
Types of functions: mathematical operations
Description: After the function passed the parameter seed, configure the random number of seeds. It is worth noting that the parameter seed value is best also a random number, such as the use of time as a variable source is a good way, or to develop other hardware peripheral interface to obtain better random numbers.
Usage examples
This example adds the time factor to the execution of the one out of 10,000 second when the random number of seeds
<?php
Srand (double) microtime () *1000000);
$randval = rand ();
echo $randval;
? >
Reference: Rand () Getrandmax () Mt_srand () Mt_rand () Mt_getrandmax ()
Tan
Tangent calculation.
Syntax: float tan (float arg);
Return values: Floating point numbers
Types of functions: mathematical operations
Description: This function calculates the tangent value of the parameter arg (tangent).
Reference: Sin () Cos ()
More interested in PHP related content readers can view the site topics: "PHP Operations and Operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", "PHP operation Office Document Skills Summary (including word,excel,access, PPT), "The PHP date and time usage summary", "PHP object-oriented Programming Introduction Course", "PHP string (String) Usage Summary", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.