You are here

public function AbstractUnitsMathematicalOperator::toInfix in Units of Measurement 7.2

Represent this mathematical expression in human-friendly infix notation.

Parameters

array $options: Options regarding how to format this mathematical expression

Return value

string Human-friendly formatted version of this mathematical expression taking into account provided $options

Overrides UnitsMathematicalExpression::toInfix

1 call to AbstractUnitsMathematicalOperator::toInfix()
UnitsMathematicalOperatorNonLinear::__construct in ./units.module
Constructor.

File

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

Class

AbstractUnitsMathematicalOperator
Abstract implementation of "mathematical operator" interface.

Code

public function toInfix($options = array()) {
  $child_options = array(
    'parent precedence' => $this->operator['precedence'],
  ) + $options;
  $output = implode(' ', array(
    $this->operand1
      ->toInfix(array(
      'operand' => 1,
    ) + $child_options),
    $this->operator['sign'],
    $this->operand2
      ->toInfix(array(
      'operand' => 2,
    ) + $child_options),
  ));
  if (isset($options['parent precedence']) && ($options['parent precedence'] > $this->operator['precedence'] || $options['operand'] == 2 && $options['parent precedence'] == $this->operator['precedence'])) {
    $output = '( ' . $output . ' )';
  }
  return $output;
}