From 0bf790cb5036809bc488a736a426376f26cee7f2 Mon Sep 17 00:00:00 2001 From: Egon Schmid Date: Thu, 7 Dec 2000 21:48:19 +0000 Subject: [PATCH] Fixed the indentation. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@37324 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/gmp.xml | 549 ++++++++++++++++++++++++---------------------- 1 file changed, 283 insertions(+), 266 deletions(-) diff --git a/functions/gmp.xml b/functions/gmp.xml index 2e3d8c28df..3811880b9a 100644 --- a/functions/gmp.xml +++ b/functions/gmp.xml @@ -1,58 +1,61 @@ GMP functions GMP - + - These functions allow you to work with arbitrary-length integers - using GNU MP library. In order to have these - functions available, you must compile PHP with - GMP - support by using the - option. + These functions allow you to work with arbitrary-length integers + using GNU MP library. In order to have these + functions available, you must compile PHP with + GMP support by using the option. - You can download the GMP library from &url.gmp;. - This site also has the GMP manual available. + You can download the GMP library from &url.gmp;. This site also has the + GMP manual available. - You will need GMP version 2 or better to use these functions. Some - functions may require more recent version of the GMP library. + You will need GMP version 2 or better to use these functions. Some + functions may require more recent version of the GMP library. - These functions have been added in PHP 4.0.4. + These functions have been added in PHP 4.0.4. - - Most GMP functions accept GMP number arguments, defined as - resource below. However, most of these functions - will accept also numeric and string arguments, given it's possible - to convert the latter to number. Also, if there's faster function that - can operate on integer arguments, it would be used instead of - slower function when supplied arguments are integers. This is done - transparently, so the bootom line is that you can use integers in - every function that expects GMP number. See also - gmp_init function. - + + + Most GMP functions accept GMP number arguments, defined as + resource below. However, most of these + functions will accept also numeric and string arguments, given + it's possible to convert the latter to number. Also, if there's + faster function that can operate on integer arguments, it would + be used instead of slower function when supplied arguments are + integers. This is done transparently, so the bootom line is that + you can use integers in every function that expects GMP + number. See also gmp_init function. + + - - Factorial function using GMP - + + Factorial function using GMP + <?php -function fact($x) { - if($x <= 1) +function fact ($x) { + if ($x <= 1) return 1; - else - return gmp_mul($x,fact($x-1)); + else + return gmp_mul ($x, fact ($x-1)); } -print gmp_strval(fact(1000))."\n"; +print gmp_strval (fact (1000)) . "\n"; ?> - - - This will calculate factiorial of 1000 (pretty big number) - very fast. - - + + + + + This will calculate factiorial of 1000 (pretty big number) + very fast. + + @@ -64,34 +67,35 @@ print gmp_strval(fact(1000))."\n"; resource gmp_init - mixed number + mixed number - Creates a GMP number from integer or string. String representation - can be decimal or hexadecimal. In the latter case, the string should - start with 0x. + Creates a GMP number from integer or string. String + representation can be decimal or hexadecimal. In the latter case, + the string should start with 0x. - - Creating GMP number - + + Creating GMP number + <?php - $a = gmp_init(123456); - $b = gmp_init("0xFFFFDEBACDFEDF7200"); + $a = gmp_init (123456); + $b = gmp_init ("0xFFFFDEBACDFEDF7200"); ?> - - - - - - It is not necessary to call this function if you want to use - integer or string in place of GMP number in GMP functions, like - gmp_add. Function arguments are automatically - converted to GMP numbers, if such conversion is possible and needed, - using the same rules as gmp_init. - - + + + + + + It is not necessary to call this function if you want to use + integer or string in place of GMP number in GMP functions, like + gmp_add. Function arguments are + automatically converted to GMP numbers, if such conversion is + possible and needed, using the same rules as + gmp_init. + + @@ -109,13 +113,14 @@ print gmp_strval(fact(1000))."\n"; - This function allows to convert GMP number to integer. - - This function returns useful result only if the number actually - fits the PHP integer (i.e., signed long type). If you want just to - print the GMP number, use gmp_strval. - - + This function allows to convert GMP number to integer. + + + This function returns useful result only if the number actually + fits the PHP integer (i.e., signed long type). If you want just + to print the GMP number, use gmp_strval. + + @@ -137,21 +142,21 @@ print gmp_strval(fact(1000))."\n"; - Convert GMP number to string representation in base - base. The default base is 10. - Allowed values for the base are from 2 to 36. + Convert GMP number to string representation in base + base. The default base is 10. Allowed + values for the base are from 2 to 36. - - Converting GMP number to string - + + Converting GMP number to string + <?php - $a = gmp_init("0x41682179fbf5"); - printf("Decimal: %s, 36-based: %s", gmp_strval($a), gmp_strval($a,36)); + $a = gmp_init("0x41682179fbf5"); + printf ("Decimal: %s, 36-based: %s", gmp_strval($a), gmp_strval($a,36)); ?> - - - + + + @@ -170,8 +175,8 @@ print gmp_strval(fact(1000))."\n"; - Add two GMP numbers. The result will be GMP number representing - the sum of the arguments. + Add two GMP numbers. The result will be GMP number representing + the sum of the arguments. @@ -191,9 +196,9 @@ print gmp_strval(fact(1000))."\n"; - Subtract b from a - and returns the result. - + Subtract b from a + and returns the result. + @@ -212,8 +217,8 @@ print gmp_strval(fact(1000))."\n"; - Multiplies a by b - and returns the result. + Multiplies a by b + and returns the result. @@ -236,37 +241,38 @@ print gmp_strval(fact(1000))."\n"; - Divides a by b - and returns the integer result. The result rounding is defined by - the round, which can have the following - values: - + Divides a by b and + returns the integer result. The result rounding is defined by the + round, which can have the following + values: + - GMP_ROUND_ZERO: The result is truncated -towards 0. + GMP_ROUND_ZERO: The result is truncated + towards 0. GMP_ROUND_PLUSINF: The result is -rounded towards +infinity. + rounded towards +infinity. GMP_ROUND_MINUSINF: The result is -rounded towards -infinity. + rounded towards -infinity. - + + + + This function can also be called as gmp_div. + + + See also gmp_div_r, + gmp_div_qr - - This function can also be called as gmp_div. - - - See also gmp_div_r, gmp_div_qr - @@ -288,17 +294,19 @@ rounded towards -infinity. - Calculates remainder of the integer division of - n by d. The remainder - has the sign of the n argument, if not zero. + Calculates remainder of the integer division of + n by d. The + remainder has the sign of the n argument, + if not zero. + + + See the gmp_div_q function for description + of the round argument. + + + See also gmp_div_q, + gmp_div_qr - - See the gmp_div_q function for description - of the round argument. - - - See also gmp_div_q, gmp_div_qr - @@ -312,39 +320,41 @@ rounded towards -infinity. array gmp_div_qr - resource n - resource d - int - round - + resource n + resource d + int + round + - The function divides n by - d and returns array, with the first element being - [n/d] (the integer result of the - division) and the second being (n - [n/d] * d) - (the remainder of the division). + The function divides n by + d and returns array, with the first + element being [n/d] (the integer result of the + division) and the second being (n - [n/d] * d) + (the remainder of the division). - - See the gmp_div_q function for description - of the round argument. - - - Division of GMP numbers - + See the gmp_div_q function for description + of the round argument. + + + + Division of GMP numbers + <?php - $a = gmp_init("0x41682179fbf5"); - $res = gmp_div_qr($a, "0xDEFE75"); - printf("Result is: q - %s, r - %s", gmp_strval($res[0]), gmp_strval($res[1])); + $a = gmp_init ("0x41682179fbf5"); + $res = gmp_div_qr ($a, "0xDEFE75"); + printf("Result is: q - %s, r - %s", + gmp_strval ($res[0]), gmp_strval ($res[1])); ?> - - - - - See also gmp_div_q, gmp_div_r. - + + + + + See also gmp_div_q, + gmp_div_r. + @@ -358,12 +368,12 @@ rounded towards -infinity. resource gmp_divexact - resource a - resource b + resource a + resource b - This function is an alias to gmp_div_q. + This function is an alias to gmp_div_q. @@ -378,14 +388,14 @@ rounded towards -infinity. resource gmp_mod - resource n - resource d + resource n + resource d - Calculates n modulo - d. The result is always non-negative, the - sign of d is ignored. + Calculates n modulo + d. The result is always non-negative, the + sign of d is ignored. @@ -400,20 +410,20 @@ rounded towards -infinity. resource gmp_divexact - resource n - resource d + resource n + resource d - Divides n by d, - using fast "exact division" algorithm. This function produces - correct results only when it is known in advance that - d divides n. + Divides n by d, + using fast "exact division" algorithm. This function produces + correct results only when it is known in advance that + d divides n. - + gmp_cmp Compare numbers @@ -423,13 +433,14 @@ rounded towards -infinity. int gmp_cmp - resource a - resource b + resource a + resource b - Returns positive value if a > b, zero if - a = b and negative value if a < b. + Returns positive value if a > b, zero if + a = b and negative value if a < + b. @@ -444,11 +455,11 @@ rounded towards -infinity. resource gmp_neg - resource a + resource a - Returns -a. + Returns -a. @@ -463,11 +474,11 @@ rounded towards -infinity. resource gmp_abs - resource a + resource a - Returns absolute value of a. + Returns absolute value of a. @@ -486,8 +497,8 @@ rounded towards -infinity. - Return sign of a - 1 if - a is positive and -1 if it's negative. + Return sign of a - 1 if + a is positive and -1 if it's negative. @@ -502,11 +513,11 @@ rounded towards -infinity. resource gmp_fact - int a + int a - Calculates factorial (a!) of a. + Calculates factorial (a!) of a. @@ -525,7 +536,7 @@ rounded towards -infinity. - Calculates square root of a. + Calculates square root of a. @@ -540,14 +551,15 @@ rounded towards -infinity. array gmp_sqrtrm - resource a + resource a - Returns array where first element is the integer square root of - a (see also gmp_sqrt), and - the second is the remainder (i.e., the difference between - a and the first element squared). + Returns array where first element is the integer square root of + a (see also + gmp_sqrt), and the second is the remainder + (i.e., the difference between a and the + first element squared). @@ -562,17 +574,17 @@ rounded towards -infinity. bool gmp_perfect_square - resource a + resource a - Returns true if a is a prefect square, - false otherwise. + Returns true if a is a prefect square, + false otherwise. + + + See also: gmp_sqrt, + gmp_sqrtrm. - - See also: gmp_sqrt, - gmp_sqrtrm. - @@ -586,14 +598,14 @@ rounded towards -infinity. resource gmp_pow - resource base - int exp + resource base + int exp - Raise base into power - exp. The case of 0^0 yields - 1. exp cannot be negative. + Raise base into power + exp. The case of 0^0 yields + 1. exp cannot be negative. @@ -608,15 +620,15 @@ rounded towards -infinity. resource gmp_powm - resource base - resource exp - resource mod + resource base + resource exp + resource mod - Calculate (base raised into power - exp) modulo mod. If - exp is negative, result is undefined. + Calculate (base raised into power + exp) modulo mod. If + exp is negative, result is undefined. @@ -631,21 +643,22 @@ rounded towards -infinity. int gmp_prob_prime - resource a - int reps + resource a + int reps - If this function returns 0, a is definitely - not prime. If it returns 1, then a is - "probably" prime. If it returns 2, then a is - surely prime. Reasonable values of reps - vary from 5 to 10 (default being 10); a higher value lowers the - probability for a non-prime to pass as a "probable" prime. + If this function returns 0, a is + definitely not prime. If it returns 1, then + a is "probably" prime. If it returns 2, + then a is surely prime. Reasonable values + of reps vary from 5 to 10 (default being + 10); a higher value lowers the probability for a non-prime to + pass as a "probable" prime. - + The function uses Miller-Rabin's probabilistic test. - + @@ -664,9 +677,9 @@ rounded towards -infinity. - Calculate greatest common divisor of a and - b. The result is always positive even if - either of or both input operands are negative. + Calculate greatest common divisor of a and + b. The result is always positive even if + either of or both input operands are negative. @@ -681,14 +694,14 @@ rounded towards -infinity. array gmp_gcdext - resource a - resource b + resource a + resource b - Calculates g, s, and t, such that - a*s + b*t = g = gcd(a,b), where gcd is gretest - common divisor. Returns array with respective elements g, s and t. + Calculates g, s, and t, such that a*s + b*t = g = + gcd(a,b), where gcd is gretest common divisor. Returns + array with respective elements g, s and t. @@ -703,13 +716,14 @@ rounded towards -infinity. resource gmp_invert - resource a - resource b + resource a + resource b - Computes the inverse of a modulo - b. Returns false if an inverse does not exist. + Computes the inverse of a modulo + b. Returns false if an inverse does not + exist. @@ -724,16 +738,16 @@ rounded towards -infinity. int gmp_legendre - resource a - resource p + resource a + resource p - Compute the - - Legendre symbol of a and - p. p should be odd - and must be positive. + Compute the + + Legendre symbol of a and + p. p should be odd + and must be positive. @@ -748,17 +762,16 @@ rounded towards -infinity. int gmp_jacobi - resource a - resource p + resource a + resource p - Computes - - Jacobi symbol of a and - p. p should be odd - and must be positive. + Computes + + Jacobi symbol of a and + p. p should be odd + and must be positive. @@ -773,13 +786,14 @@ rounded towards -infinity. resource gmp_random - int limiter + int limiter - Generate a random number. The number will be up to - limiter words long. If - limiter is negative, negative numbers are generated. + Generate a random number. The number will be up to + limiter words long. If + limiter is negative, negative numbers are + generated. @@ -794,12 +808,12 @@ rounded towards -infinity. resource gmp_and - resource a - resource b + resource a + resource b - Calculates logical AND of two GMP numbers. + Calculates logical AND of two GMP numbers. @@ -814,12 +828,12 @@ rounded towards -infinity. resource gmp_or - resource a - resource b + resource a + resource b - Calculates logical inclusive OR of two GMP numbers. + Calculates logical inclusive OR of two GMP numbers. @@ -834,12 +848,12 @@ rounded towards -infinity. resource gmp_xor - resource a - resource b + resource a + resource b - Calculates logical exclusive OR (XOR) of two GMP numbers. + Calculates logical exclusive OR (XOR) of two GMP numbers. @@ -854,15 +868,18 @@ rounded towards -infinity. resource gmp_setbit - resource &a - int index - bool set_clear + resource &a + int index + bool + set_clear + - Sets bit index in - a. set_clear defines - if the bit is set to 0 or 1. By default the bit is set to 1. + Sets bit index in + a. set_clear + defines if the bit is set to 0 or 1. By default the bit is set to + 1. @@ -877,13 +894,13 @@ rounded towards -infinity. resource gmp_clrbit - resource &a - int index + resource &a + int index - Clears (sets to 0) bit index in - a. + Clears (sets to 0) bit index in + a. @@ -898,15 +915,15 @@ rounded towards -infinity. int gmp_scan0 - resource a - int start + resource a + int start - Scans a, starting with bit - start, towards more significant - bits, until the first clear bit is found. Returns the index of the - found bit. + Scans a, starting with bit + start, towards more significant bits, + until the first clear bit is found. Returns the index of the + found bit. @@ -921,20 +938,20 @@ rounded towards -infinity. int gmp_scan1 - resource a - int start + resource a + int start - Scans a, starting with bit - start, towards more significant - bits, until the first set bit is found. Returns the index of the - found bit. + Scans a, starting with bit + start, towards more significant bits, + until the first set bit is found. Returns the index of the found + bit. - + gmp_popcount Population count @@ -944,11 +961,11 @@ rounded towards -infinity. int gmp_popcount - resource a + resource a - Return the population count of a. + Return the population count of a. @@ -963,13 +980,13 @@ rounded towards -infinity. int gmp_hamdist - resource a - resource b + resource a + resource b - Returns the hamming distance between a and - a. Both operands should be non-negative. + Returns the hamming distance between a and + a. Both operands should be non-negative.