You are here

protected function IngredientQuantityUtility::getGcd in Recipe 8.2

Finds the greatest common divisor of two numbers.

Parameters

int $a: The initial dividend of the operation.

int $b: The initial divisor of the operation.

Return value

int The greatest common divisor of $a and $b.

1 call to IngredientQuantityUtility::getGcd()
IngredientQuantityUtility::getQuantityFromDecimal in modules/ingredient/src/Utility/IngredientQuantityUtility.php
Converts an ingredient's quantity from decimal to fraction.

File

modules/ingredient/src/Utility/IngredientQuantityUtility.php, line 122

Class

IngredientQuantityUtility
Provides the ingredient.quantity service.

Namespace

Drupal\ingredient\Utility

Code

protected function getGcd($a, $b) {
  while ($b != 0) {
    $remainder = $a % $b;
    $a = $b;
    $b = $remainder;
  }
  return abs($a);
}