Return number as Rational number.
NB, numerator and denominator will be caste as IntTypes

@return \Chippyash\Type\Number\Rational\RationalType
768863
public function asRational()
    {
        if (RequiredType::getInstance()->get() == RequiredType::TYPE_NATIVE) {
            return new RationalType(clone $this, new static(1));
        }

        return new GMPRationalType(new GMPIntType($this->value), new GMPIntType(1));
    }
1148575
public function sqrt()
    {
        $newValue = bcsqrt($this->getValue(), $this->getScale());

        return $this->assignValue($newValue);
    }
640261
public function getResultingType() : \Dms\Core\Persistence\Db\Schema\Type\Type
    {
        return Integer::normal();
    }
604407
public function readInt() {
            
            $int = $this->readU29();
            // if int and has the sign bit set
            // Check if the integer is an int
            // and is signed
            if (($int & 0x18000000) == 0x18000000) {
                $int ^= 0x1fffffff;
                $int *= -1;
                $int -= 1;
            } else if (($int & 0x10000000) == 0x10000000) {
                // remove the signed flag
                $int &= 0x0fffffff;
            }

            return $int;

        }
489455
public function get()
    {
        if ($this->isInteger()) {
            /** @noinspection PhpUndefinedMethodInspection */
            return $this->value['num']->get();
        }

        $num = intval(gmp_strval($this->value['num']->gmp()));
        $den = intval(gmp_strval($this->value['den']->gmp()));

        return $num/$den;
    }
766874
public function toInteger()
    {
        if (0 === gmp_cmp($this->value, gmp_init(0))) {
            return '';
        }

        $temp = gmp_strval(gmp_abs($this->value), 10);

        return (int) $temp;
    }
497480
protected function getNumberFormatter()
    {
        $formatter = parent::getNumberFormatter();

        $formatter->setSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, $this->thousandsSeparator);
        $formatter->setSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL, $this->decimalSeparator);
        $formatter->setPattern(sprintf('#%s##0%s###', $this->thousandsSeparator, $this->decimalSeparator));

        return $formatter;
    }
284842
protected function getNumberFormatter()
    {
        $formatter = new \NumberFormatter($this->locale, \NumberFormatter::DECIMAL);

        if (null !== $this->precision) {
            $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision);
            $formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $this->roundingMode);
        }

        $formatter->setAttribute(\NumberFormatter::GROUPING_USED, $this->grouping);

        return $formatter;
    }
1069973
private function divideInt(int $int): Rational
    {
        $w = $this->whole;
        $n = $this->numerator;
        $d = $this->denominator;
        return new Rational(0, $w * $d + $n, $int * $d);
    }
123289
protected function _decimal()
    {
        $sign = 1;

        if ($this->value < 0) {
            $sign = -1;
        }

        return new N($sign * (abs($this->value) - floor(abs($this->value))));
    }
371914
public function primeFactors()
    {
        // max_n = 2^31-1 = 2147483647
        $number = $this->value;
        $divisor = 2;
        $factors = array();
        $dmax = floor(sqrt($number));
        $sieve = array_fill(1, $dmax, 1);
        do {
            $rFlag = false;
            while ($number % $divisor == 0) {
                $factors[$divisor] = (isset($factors[$divisor]) ? $factors[$divisor] + 1 : 1);
                $number /= $divisor;
                $rFlag = true;
            }
            if ($rFlag) {
                $dmax = floor(sqrt($number));
            }
            if ($number > 1) {
                for ($i = $divisor; $i <= $dmax; $i += $divisor) {
                    $sieve[$i] = 0;
                }
                do {
                    $divisor ++;
                } while ($divisor < $dmax && $sieve[$divisor] != 1);
                if ($divisor > $dmax) {
                    $factors[$number] = (isset($factors[$number]) ? $factors[$number] + 1 : 1);
                }
            }
        } while ($number > 1 && $divisor <= $dmax);

        return $factors;
    }
1109156
public static function pi(): Decimal
    {
        if (null === self::$PI) {
            self::$PI = Decimal::fromString(
                "3.14159265358979323846264338327950"
            );
        }
        return self::$PI;
    }
598529
public function toUnit()
    {
        if ($this->divisibility <= 0)
            return $this->toMicro();

        $div = pow(10, $this->getDivisibility());
        return ($this->toMicro() / $div);
    }
411770
public function getTypesWithCount() {
		$query = $this->find();
		$types = $query
			->select(['type', 'count' => 'COUNT(*)'])
			->distinct('type')
			->order('type ASC')
			->disableHydration()
			->toArray();

		return Hash::combine($types, '{n}.type', '{n}.count');
	}
506625
public function rationalAdd(NI $a, NI $b)
    {
        if (!$a instanceof RationalType) {
            $a = $a->asRational();
        }
        if (!$b instanceof RationalType) {
            $b = $b->asRational();
        }

        $d = RationalTypeFactory::create($this->lcm($a->denominator()->get(), $b->denominator()->get()));
        $nn = $this->rationalDiv($this->rationalMul($a->numerator(), $d), $a->denominator())->get();
        $nd = $this->rationalDiv($this->rationalMul($b->numerator(), $d), $b->denominator())->get();
        $n = $this->intAdd(new IntType($nn), new IntType($nd));

        return RationalTypeFactory::create($n, $d->numerator());
    }
1152077
public function intSqrt(IntType $a)
    {
        $res = $this->rationalSqrt(new RationalType($a, new IntType(1)));
        if ($res->isInteger()) {
            return $res->numerator();
        }

        return $res;
    }
1340321
public function getCeil()
	{
		if ( $this->getIsDecimal() === false )
		{
			return $this;
		}

		if ( $this->getIsNegative() === true )
		{
			return new DecimalValue( bcadd( $this->_value, '0', 0 ) );
		}

		return new DecimalValue( bcadd( $this->_value, '1', 0 ) );  // Add one and truncate
	}