private function normalize()
    {
        $gcd = Math::gcd($this->p, $this->q);

        if ($gcd == 0) throw new DivisionByZeroException();

        $this->p = $this->p/$gcd;
        $this->q = $this->q/$gcd;

        if ($this->q < 0) {
            $this->p = -$this->p;
            $this->q = -$this->q;
        }
    }
private function normalize()
    {
        $gcd = Math::gcd($this->p, $this->q);

        if ($gcd == 0) throw new DivisionByZeroException();

        $this->p = $this->p/$gcd;
        $this->q = $this->q/$gcd;

        if ($this->q < 0) {
            $this->p = -$this->p;
            $this->q = -$this->q;
        }
    }
private function normalize ( ) { $ gcd = Math :: gcd ( $ this -> p , $ this -> q ) ; if ( $ gcd == 0 ) throw new DivisionByZeroException ( ) ; $ this -> p = $ this -> p / $ gcd ; $ this -> q = $ this -> q / $ gcd ; if ( $ this -> q < 0 ) { $ this -> p = - $ this -> p ; $ this -> q = - $ this -> q ; } }
Normalize, i.e. make sure the denominator is positive and that
the numerator and denominator have no common factors
Normalize i . e . make sure the denominator is positive and that the numerator and denominator have no common factors