1. Computing
Send to a Friend via Email

The Pi () function and M_PI

By

Top Related Searches

The PI () Function:

The PI () function is used in many mathematical calculations and is approximately equal to 3.14159265358979323846. By default it will use a precision of 14 decimals, however this can be changed and set as high as 20 in the php.ini file. Here are some examples of it in use:
 <?php 
 echo pi() ;
 echo "<br>";
 echo pi () * 4;
 ?> 

Using M_PI:

M_PI is a constant that will produce the same value as PI (). Our previous example could be rewritten using M_PI like this:
 <?php 
 echo M_PI;
 echo "<br>";
 echo M_PI * 4;
 ?> 

Other Variations:


M_PI_2 = Half of PI ()
M_PI_4 = One Quarter PI ()
M_1_PI =One divided by PI ()
M_2_PI = Two divided by PI ()
M_SQRTPI = Square root of PI ()
M_2_SQRTPI = Two Divided by the square root of PI ()
Related Video
Using PHP With HTML
Basic PHP Syntax

©2014 About.com. All rights reserved.