/** * @param Unit $unit * @param int $root * @param string $quantity * @param string $symbol * * @return CompoundUnit */ public static function getRootInstance(Unit $unit, $root, $quantity = '', $symbol = '') { if ($unit instanceof CompoundUnit) { $elements = []; foreach ($unit->getElements() as $element) { $gcd = self::gcd(abs($element->pow), $element->root * $root); $elements[] = new CompoundElement($element->unit, $element->pow / $gcd, $element->root * $root / $gcd); } } else { $elements = [new CompoundElement($unit, 1, $root)]; } return self::getInstance($elements, [], $quantity, $symbol); }