You are here

public function UnitsMathematicalOperatorNonLinear::decompose in Units of Measurement 7.2

Decompose (simplify) this mathematical expression.

Return value

UnitsMathematicalExpression Decomposed (simplified) version of this mathematical expression

Overrides AbstractUnitsMathematicalOperator::decompose

File

./units.module, line 1676
Provide API for managing and converting units of measurement.

Class

UnitsMathematicalOperatorNonLinear
Implementation of "mathematical operator" interface for non-linear operation.

Code

public function decompose() {
  $unit = $this
    ->nonLinearMember();

  // This is somewhat hacky, but it's the best I could come up with. We will
  // temporarily swap decomposition expression in the unit with the specific
  // quantity and then will invoke the decomposition on the unit.
  $temporary_decomposition = $unit->decomposition;
  $unit->decomposition = units_mathematical_expression_create_from_postfix(str_replace(UNITS_QUANTITY, $this
    ->linearMember()
    ->toPostfix(), $unit->decomposition
    ->getExpression()
    ->toPostfix()));
  $decomposition = $unit
    ->decompose();
  $unit->decomposition = $temporary_decomposition;
  return $decomposition;
}