You are here

public function Fraction::reciprocate in Fraction 2.x

Same name and namespace in other branches
  1. 8 src/Fraction.php \Drupal\fraction\Fraction::reciprocate()

Reciprocates the fraction.

Return value

Fraction Returns this Fraction object.

Overrides FractionInterface::reciprocate

File

src/Fraction.php, line 242

Class

Fraction
A simple class for representing and acting upon a fraction.

Namespace

Drupal\fraction

Code

public function reciprocate() {

  // Get the numerator and denominator, but flipped.
  $numerator = $this
    ->getDenominator();
  $denominator = $this
    ->getNumerator();

  // Save the numerator and denominator.
  $this
    ->setNumerator($numerator);
  $this
    ->setDenominator($denominator);
  return $this;
}