Karlos94
06-07-2010, 10:16 AM
Well I got bored this morning as I only have to go into school for exams and I have one today, maths! So I was wondering how I could help myself remember the formula to calculate the area of a circle and the circumference of a circle. So I was browsing this forum and I saw LordDan post a mathematics function to calculate percentage so I thought to myself that I should do this with the formula and create two functions. I ended up writing these functions and I have tested them but I would like to improve them if others are kind enough to give feedback and other ideas.
Constructive criticism is welcome, flaming is not.
<?php
## Created by Karl Ballard
function area_of_circle($val, $radius = true, $dec_return = 3)
{
if (!is_numeric($val))
{
return false;
}
if (!is_numeric($pi))
{
$pi = pi();
}
if ($radius === false)
{
$val = $val / 2;
}
return $dec_return === false ? $pi * $val * $val : number_format($pi * $val * $val, $dec_return);
}
## Created By Karl Ballard
function circum_of_circle($val, $radius = false, $dec_return = 3)
{
if (!is_numeric($val))
{
return false;
}
if (!is_numeric($pi))
{
$pi = pi();
}
if ($radius === true)
{
$val = $val * 2;
}
return $dec_return === false ? $pi * $val : number_format($pi * $val, $dec_return);
}
Constructive criticism is welcome, flaming is not.
<?php
## Created by Karl Ballard
function area_of_circle($val, $radius = true, $dec_return = 3)
{
if (!is_numeric($val))
{
return false;
}
if (!is_numeric($pi))
{
$pi = pi();
}
if ($radius === false)
{
$val = $val / 2;
}
return $dec_return === false ? $pi * $val * $val : number_format($pi * $val * $val, $dec_return);
}
## Created By Karl Ballard
function circum_of_circle($val, $radius = false, $dec_return = 3)
{
if (!is_numeric($val))
{
return false;
}
if (!is_numeric($pi))
{
$pi = pi();
}
if ($radius === true)
{
$val = $val * 2;
}
return $dec_return === false ? $pi * $val : number_format($pi * $val, $dec_return);
}