Php Math Examples Calling the Built-in abs() Function abs( ) function returns the absolute value of the parameter You can either send a floating-point number or an integer to abs( ) float acos ( float num ) calculates the arc cosine value float asin ( float num ) calculates the arc sine value float atan ( float num ) calculates the arc tangent value Convert integer values to other bases such as binary or base 32 and base 36 string base_convert ( string num, int from_base, int to_base ) convert every base to every other base function base_convert() converts any integer value from one base to another BCMath Functions Doing math with the bcmath extension float ceil ( float num ) rounds parameter to the nearest integer above its current value float cos ( float num ) calculates the cosine value of the number provided as its only parameter. The parameter should be passed as radiansyou should use deg2rad( ) to convert degrees to radians. string decbin ( int num ) converts a decimal number into a binary number number decbin ( string binary_num ) converts a binary number into a decimal number string dechex ( int num ) converts a decimal number into a binary number string decoct ( int num ) converts a decimal number into an octal number Constants and switch statement Constants, like the names of variables, are case-sensitivebut unlike variables Define a constant as an array or object float deg2rad ( float num ) converts degrees to radians. Return the distance between two locations in either kilometers or miles rand demo Using the arbitrary-precision functions for exact integer arithmetic Difference between ceil and floor Floor in action Round in action Get the Power float floor ( float num ) rounds it to the nearest integer below its current value Both random generators provide functions to get the value of MAX_RAND. number hexdec ( string hex_string ) converts a hexadecimal number into a decimal number Calculate logarithms with other base values by dividing the result of the log() function with log(base). Calculation of e, the inverse nature of exp and log calculate logarithms by dividing log() function with log(base) Math calculation Math operations Mathematical constants Hyperbolic Functions Finding the Greatest and Least Values in a key-value pair Finding the Greatest and Least Values in an Array Random generators provide functions to get the value of MAX_RAND int mt_rand ( [int min, int max] ) returns random numbers, similar to the rand( ). Finding a random line of a file Generate random floating-point values from 0 to 10 with two decimals Generate random numbers Get a random value from 5 to 25. Generate Password() Get random values from –10 to 10. Random floating-point values from 0 to 10 with two decimals Random numbe with precision Random values are not restricted to positive integers. The following example shows how to get random values from -10 to 10. Using the pow() function with integers, floats, and both negative and positive numbers. number pow ( number base, number exponent), a base and a power to raise it by float rad2deg ( float num ) converts radians to degrees Dice Rolling Simulator Generate random numbers (integer values) between 0 and MAX_RAND by calling rand() or mt_rand() without any arguments int rand ( [int min, int max] ) returns random numbers Random Images Random Numbers mt_rand with no arguments mt_rand with two arguments round a double float round ( float num [, int precision] ) rounds parameter to the nearest integer to its current value Provide the number of decimal places to round to doubles can be specified in scientific notation float sin ( float num ) calculates the sine value of the number provided as its only parameter Using the trigonometric functions float tan ( float num ) calculates the tangent value of the number

Php Code : Using The Arbitrary-precision Functions For Exact Integer Arithmetic

Using the arbitrary-precision functions for exact integer arithmetic in php

<?
for ($x = 1; $x < 25; $x++) {
  print("$x to the $x power is " . bcpow($x, $x) . "<BR>");
}

?>