function recipe_euclid in Recipe 5
1 call to recipe_euclid()
- recipe_ingredient_quantity_from_decimal in ./
recipe.module - Converts an ingredient's quantity from decimal to fraction
File
- ./
recipe.module, line 1557 - recipe.module - share recipes for drupal 5.x
Code
function recipe_euclid($number_one, $number_two) {
if ($number_one == 0 or $number_two == 0) {
$hcf = 1;
return $hcf;
}
else {
if ($number_one < $number_two) {
$buffer = $number_one;
$number_one = $number_two;
$number_two = $buffer;
}
$dividend = $number_one;
$divisor = $number_two;
$remainder = $dividend;
while ($remainder > 0) {
if (floor($dividend / $divisor) == $dividend / $divisor) {
$quotient = $dividend / $divisor;
$remainder = 0;
}
else {
$quotient = floor($dividend / $divisor);
$remainder = $dividend - $quotient * $divisor;
}
$hcf = $divisor;
$dividend = $divisor;
$divisor = $remainder;
}
}
return $hcf;
}