This is a discussion on Mathematical functions in PHP within the PHP Programming forums, part of the Web Development category; pi() returns an approximation of pi. The returned float has a precision based on the precision directive in php.ini, ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| pi() returns an approximation of pi. The returned float has a precision based on the precision directive in php.ini, which defaults to 14. Also, you can use the M_PI constant which yields identical results to pi(). PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
| |||
| log() - Natural logarithm If the optional base parameter is specified, log() returns logbase arg, otherwise log() returns the natural logarithm of arg.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| As always you can calculate the logarithm in base b of a number n, but using the mathematical identity: logb(n) = log(n)/log(b), where log is the neperian (or natural) logarithm.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| The log() The log() function returns the natural logarithm (base E) of a number. Syntax log(x,base) Example In the following example we will use the log() function on different numbers: <?php echo(log(2.7183) . "<br />"); echo(log(2) . "<br />"); echo(log(1) . "<br />"); echo(log(0) . "<br />"); echo(log(-1)) ?>
__________________ Thanks Regards Sureshbabu Harikrishnan ![]() +91 9884320017 |
| |||
| For arbitrary precision mathematics PHP offers the Binary Calculator which supports numbers of any size and precision, represented as strings.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| These functions are only available if PHP was configured with --enable-bcmath. In PHP 3, these functions are only available if PHP was not configured with --disable-bcmath. The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| bcadd() adds the left_operand to the right_operand and returns the sum in a string. The optional scale parameter is used to set the number of digits after the decimal place in the result. For example: PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| <?php echo decoct("30") . "<br />"; echo decoct("10") . "<br />"; echo decoct("1587") . "<br />"; echo decoct("70"); ?> It convert decimal number into octal number output is 36 12 3063 106 |
| |||
| <?php echo octdec("36") . "<br />"; echo octdec("12") . "<br />"; echo octdec("3063") . "<br />"; echo octdec("106"); ?> It converts an octal number to a decimal number output 30 10 1587 70 |
| |||
| <?php echo dechex("30") . "<br />"; echo dechex("10") . "<br />"; echo dechex("1587") . "<br />"; echo dechex("70"); ?> IT convert decimal number into hexadecimal number output 1e a 633 46 |
| |||
| bccomp() compares the left_operand to the right_operand and returns the result as an integer. The optional scale parameter is used to set the number of digits after the decimal place which will be used in the comparison. The return value is 0 if the two operands are equal. If the left_operand is larger than the right_operand the return value is +1 and if the left_operand is less than the right_operand the return value is -1. For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| bcdiv() divides the left_operand by the right_operand and returns the result. The optional scale sets the number of digits after the decimal place in the result, which defaults to 0. For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| bcmul() Multiply two arbitrary precision number and Multiply the left_operand by the right_operand and returns the result. The optional scale sets the number of digits after the decimal place in the result. For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Hi log10() The log10() function returns the base-10 logarithm of a number. for example PHP Code: Code: 0.434297385125 0.301029995664 0 -1.#INF -1.#IND Falcon ![]() |
| |||
| hypot() The hypot() function returns the length of the hypotenuse of a right-angle triangle. Syntax hypot(x,y) Example <?php echo hypot(2,3) . "<br />"; echo hypot(3,6) . "<br />"; echo hypot(3,6) . "<br />"; echo hypot(1,3); ?> The output of the code above will be: 3.60555127546 6.7082039325 6.7082039325 3.16227766017
__________________ Thanks Regards Sureshbabu Harikrishnan ![]() +91 9884320017 |
| |||
| mt_rand() The mt_rand() function returns a random integer using the Mersenne Twister algorithm. If this function is called without parameters, it returns a pseudo-random value between 0 and RAND_MAX. If you want a random number between 10 and 100 (inclusive), use mt_rand (10,100). Syntax mt_rand(min,max) Example In this example we will return some random numbers: <?php echo(mt_rand() . "<br />"); echo(mt_rand() . "<br />"); echo(mt_rand(10,100)) ?> The output of the code above could be: 1150905288 613289478 21
__________________ Thanks Regards Sureshbabu Harikrishnan ![]() +91 9884320017 |
| |||
| bcmod() Get modulus of an arbitrary precision number For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| bcpow() Raise an arbitrary precision number to another Raise x to the power y For e.g PHP Code:
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| expm1() The expm1() function returns the value of Ex-1, where E is Euler's constant (approximately 2.7183) and x is the number passed to it. Syntax expm1(x) Parameter Description x Required. A number Example In the following example we will use the expm1() function on different numbers: <?php echo(expm1(1) . "<br />"); echo(expm1(-1) . "<br />"); echo(expm1(5) . "<br />"); echo(expm1(10)) ?>
__________________ Thanks Regards Sureshbabu Harikrishnan ![]() +91 9884320017 |
| |||
| bcpowmod() Raise an arbitrary precision number to another, reduced by a specified modulus Use the fast-exponentiation method to raise x to the power y with respect to the modulus modulus. The optional scale can be used to set the number of digits after the decimal place in the result. Because this method uses the modulus operation, non-natural numbers may give unexpected results. A natural number is any positive non-zero integer.
__________________ With, J. Jeyaseelan Everything Possible |