Simple And Basic Numerical Functions in PHP

This is the tutorial to do simple and basic numerical functions in Math. You might want to use these functions for your website or create your own algorithm by using these math functions.

For better understanding, we will just go through the coding right away. Explanation has been written in the coding. So, you don't to worry. Simply copy and paste the coding and run it or you can use online PHP compiler by clicking HERE to run the coding below.


//Ceiling and Floor.
//According to Wikipedia, Floor  is the largest integer not greater than x and Ceiling is the smallest integer not less than x. Source:
echo "<p>The ceil of $number1 is ". ceil($number1) ."</p>";
echo "<p>The floor of $number1 is ". floor($number1) ."</p>";

//absolute: |number|
//Explanation from Wikipedia here:
echo "<p>The absolute of $number1 is ". abs($number1) ."</p>";
echo "<p>The absolute of $number2 is ". abs($number2) ."</p>";

//power of: raise one number to the power of another
//e.g.: 2^3=8
echo "<p>5<sup>3</sup> is ". pow(5,3) ."</p>";

//Exponent here is almost the same like the functions pow above. 
//The exp() function returns e raised to the power of x (e^x).
//'e' is the base of the natural system of logarithms (approximately 2.718282) and x is the number passed to it.
echo "<p>The exponent of 10 = ". exp(10) ."</p>";

//logarithm e.g.:log2(8)
echo "<p>log<sub>2</sub>(8) = ". log(8,2) ."</p>";
echo "<p>log<sub>10</sub>(100) = ". log(100,10) ."</p>";


Happy Coding and Good Luck!

Labels: , , , , ,