PI() : Constant Value

PI();
Contstant value equal to 3.1415926535898.
<?Php
echo PI(); // Output is 3.14159265358983
echo M_PI; // Output is 3.1415926535898
?>

PI() with ROUND()

Math function Round is used to manage decimal places

<?Php
echo round(PI(),2); // Output is 3.14
echo "<br>";
echo round(PI()/2,2); // Output is 1.57
echo "<br>";
echo round(M_PI_4,2); // Output is 0.79 
?>

Values of M_PI

echo M_PI_2; // Output is 1.5707963267949 // same as PI()/2
echo "<br>";
echo M_PI_4; // Output is 0.78539816339745 // same as PI()/4
echo M_1_PI; // Output is 1.5707963267949 // same as 1/PI()
echo "<br>";
echo M_2_PI; // Output is 0.78539816339745 // same as 2/PI()

rad2deg with PI()

Converting Rading to degree by rad2deg()

echo rad2deg(PI()); // Output is 180
echo "<br>";
echo rad2deg(PI()/2); // Output is 90
echo "<br>";
echo rad2deg(PI()/3); // Output is 60
echo "<br>";
echo rad2deg(PI()/4); // Output is 45

PI() with sin() cos()

Decimal places Sin(), cos() and other trigonometric functions takes input in radian and give sin and cosine values of angles .
<?Php
echo round(sin(pi()),2);// Output  is 0
echo "<br>";
echo sin(pi()/2); // Output  is 1
echo "<br>";
echo cos(pi()); // Output  is -1
echo "<br>";
echo round(cos(PI()/2),2); // Output  is 0
?>
We used Round function to manage decimal places.

Plotting of SIN & COS curves by using PHP GD function with deg2rad()

Your Rating





Post Comment This is for short comments only. Use the forum for more discussions.




HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer