Add a rational number

@param Rational $r

@return Rational
507731
private function addRational(Rational $r): Rational
    {
        $w = $this->whole;
        $n = $this->numerator;
        $d = $this->denominator;

        $rn = $r->numerator;
        $rd = $r->denominator;
        $rw = $r->whole;

        $w += $rw;

        $lcm = Algebra::lcm($d, $rd);
        $n = $n * intdiv($lcm, $d) + $rn * intdiv($lcm, $rd);
        $d = $lcm;

        return new Rational($w, $n, $d);
    }
698482
public function add($number = null)
    {
        if ($number == null) {
            $this->internalSetOperationModeWithHistory('add');
        } elseif ($number instanceof Closure) {
            $this->internalSetOperationModeWithHistory('add');
            return $this->group($number);
        } else {
            $this->performOperationOnExpressionEngine('add', $number);
        }
        return $this;
    }
132018
public function multipliedBy($that) : RationalMoney
    {
        $amount = $this->amount->multipliedBy($that);

        return new self($amount, $this->currency);
    }
534832
public Rational plus(final Rational pOther) {
        // special cases
        if (equals(ZERO)) {
            return pOther;
        }
        if (pOther.equals(ZERO)) {
            return this;
        }

        // Find gcd of numerators and denominators
        long f = gcd(numerator, pOther.numerator);
        long g = gcd(denominator, pOther.denominator);

        // add cross-product terms for numerator
        // multiply back in
        return new Rational(
                ((numerator / f) * (pOther.denominator / g) + (pOther.numerator / f) * (denominator / g)) * f,
                lcm(denominator, pOther.denominator)
        );
    }
656611
public static function add($z, $w) {
        if (!($z instanceof Complex)) $z = static::parse($z);
        if (!($w instanceof Complex)) $w = static::parse($w);

        return static::create($z->x + $w->x, $z->y + $w->y);
    }
876978
public Rational multiply(final int val) {
        BigInteger tmp = BigInteger.valueOf(val);
        return multiply(tmp);
    }
213665
public function initFromRgba($r, $g, $b, $a = 1)
    {
        $this->r = (int) $r;
        $this->g = (int) $g;
        $this->b = (int) $b;
        $this->a = $this->alpha2gd($a);

        return $this;
    }
623423
private function complexExponent($base, ComplexType $exp)
    {
        if ($exp->isReal()) {
            return $this->rationalPow(
                RationalTypeFactory::fromFloat($base),
                $exp->r()
            );
        }

        //do the imaginary part
        //n^bi = cos(b.lg(n)) + i.sin(b.lg(n))
        $b = $exp->i()->get();
        $n = log($base);
        $r = cos($b * $n);
        $i = sin($b * $n);

        //no real part
        if ($exp->r()->get() == 0) {
            return new ComplexType(
                RationalTypeFactory::fromFloat($r),
                RationalTypeFactory::fromFloat($i)
            );
        }
        //real and imaginary part
        //n^a+bi = n^a(cos(b.lg(n)) + i.sin(b.lg(n)))
        $na = pow($base, $exp->r()->get());
        $rr = $na * $r;
        $ii = $na * $i;
        return new ComplexType(
            RationalTypeFactory::fromFloat($rr),
            RationalTypeFactory::fromFloat($ii)
        );
    }
409865
public static function fromFloat($float, $tolerance=1e-7)
    {
        if (is_string($float) && preg_match('~^\-?\d+([,|.]\d+)?$~', $float)) {
            $float = floatval(str_replace(',','.',$float));
        }

        if ($float == 0.0) {
            return new Rational(0,1);
        }
        $negative = ($float < 0);
        if ($negative) {
            $float = abs($float);
        }
        $num1 = 1;
        $num2 = 0;
        $den1 = 0;
        $den2 = 1;
        $oneOver = 1 / $float;
        do {
            $oneOver = 1 / $oneOver;
            $floor = floor($oneOver);
            $aux = $num1;
            $num1 = $floor * $num1 + $num2;
            $num2 = $aux;
            $aux = $den1;
            $den1 = $floor * $den1 + $den2;
            $den2 = $aux;
            $oneOver = $oneOver - $floor;
        } while (abs($float - $num1 / $den1) > $float * $tolerance);
        if ($negative) {
            $num1 *= -1;
        }

        return new Rational(intval($num1), intval($den1));
    }
197658
public function add($a, $b)
    {
        return bcadd($this->bcNormalize($a), $this->bcNormalize($b));
    }
1183286
public Rational times(final Rational pOther) {
        // special cases
        if (equals(ZERO) || pOther.equals(ZERO)) {
            return ZERO;
        }

        // reduce p1/q2 and p2/q1, then multiply, where a = p1/q1 and b = p2/q2
        Rational c = new Rational(numerator, pOther.denominator);
        Rational d = new Rational(pOther.numerator, denominator);

        return new Rational(c.numerator * d.numerator, c.denominator * d.denominator);
    }
653635
def add(self, r):
        ''''''
        id = r.get_residue_id()
        if self.order:
            last_id = self.order[-1]

            # KAB - allow for multiresidue noncanonicals
            if id in self.order:
                raise colortext.Exception('Warning: using code to "allow for multiresidue noncanonicals" - check this case manually.')
                id = '%s.%d'%(str(id),self.special_insertion_count)
                self.special_insertion_count += 1

            assert(r.Chain == self.sequence[last_id].Chain)
            assert(r.residue_type == self.sequence[last_id].residue_type)
        self.order.append(id)
        self.sequence[id] = r
715529
public function add(...$numbers)
    {
        foreach ($numbers as $number) {
            $this->number = bcadd($this->number, static::validateInputNumber($number), $this->precision);
        }

        return $this;
    }
487725
public function add($interval)
    {
        parent::add($interval);

        if ($interval instanceof DateInterval) {
            if ($interval->invert) { // is negative, then sub
                $this->subMicroseconds($interval->u);
            } else {
                $this->addMicroseconds($interval->u);
            }
        }

        return $this;
    }
1271473
public function equals(Rational $rn): bool
    {
        return $this->whole       == $rn->whole        &&
               $this->numerator   == $rn->numerator    &&
               $this->denominator == $rn->denominator;
    }
1097502
public function theta()
    {
        return RationalTypeFactory::fromFloat(
            atan2(
                $this->value['imaginary']->asFloatType()->get(),
                $this->value['real']->asFloatType()->get()
            )
        );
    }
34764
public static function createFloat($value)
    {
        if ($value instanceof NumericTypeInterface) {
            return $value->asFloatType();
        }
        if (!is_numeric($value)) {
            throw new \InvalidArgumentException("'{$value}' is no valid numeric for FloatType");
        }
        
        if (self::getRequiredType() == self::TYPE_GMP) {
            return RationalTypeFactory::create($value);
        }
        
        return new FloatType($value);
    }