Math Functions

Learn Math Functions in PHP

<?php
$check = is_numeric(‘M_PI * 3’);
if($check)
echo “yes numeric”;
else
echo “no numeric”;

echo “<br / ><hr>”;
$check = M_PI * 3;

if(is_numeric($check))
echo “yes numeric”;
else
echo “no numeric”;

echo “<br / ><hr>”;
$check = is_numeric(‘123456’);

if($check)
echo “yes numeric”;
else
echo “no numeric”;

/* same way
is_int
is_float */

$check = is_float(‘4.23’);
echo “<br / ><hr>”;
if($check)
echo “yes float”;
else
echo “no float”;

$check = is_float(4.23);
echo “<br / ><hr>”;
if($check)
echo “yes float”;
else
echo “no float”;

echo “<br / ><hr>”;

echo bindec(101110);

echo “<br / ><hr>”;

echo decbin(46);

echo “<br / ><hr>”;

// same way octdec() and decoct() , hexdec() and dechex() will work

echo pow(4,2) . “<br />”;
echo pow(6,2) . “<br />”;
echo pow(-6,2) . “<br />”;
echo pow(-6,-2) . “<br />”;
echo pow(-6,5.5). “<br />”;
echo pow(25,25);
echo “<br / ><hr>”;

echo “The exp() function returns the value of E^x, where E is Euler’s constant (approximately 2.7183) and x is the number passed to it.<br/>”;
echo(exp(1) . “<br />”);
echo(exp(-1) . “<br />”);
echo(exp(5) . “<br />”);
echo(exp(10));

echo “<br / ><hr>”;
echo “The log() function returns the natural logarithm (base E) of a number.<br/>”;
echo(log(2.7183) . “<br />”);
echo(log(2) . “<br />”);
echo(log(1) . “<br />”);
echo(log(0) . “<br />”);
echo(log(-1));

echo “<br / ><hr>”;
echo “The log10() function returns the base-10 logarithm of a number.<br/>”;
echo(log10(2.7183) . “<br />”);
echo(log10(2) . “<br />”);
echo(log10(1) . “<br />”);
echo(log10(0) . “<br />”);
echo(log10(-1));

echo “<br / ><hr>”;
echo “bc functions are used for arbitray function<br/> “;
bcscale(3); //sets the scale factor for subsequent BC function calls.
echo bcpow(25,25). “<br />”;
echo bcadd(“123456789″,”12345678912345678”). “<br />”;
echo bcadd(“123456789″,”12345678912345678”,0);

?>

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.