BigRational constructor

BigRational(
  1. BigInt numerator, {
  2. BigInt? denominator,
})

Constructs a BigRational instance from the given numerator and optional denominator.

Implementation

factory BigRational(BigInt numerator, {BigInt? denominator}) {
  if (denominator == null) {
    return BigRational._(numerator, _one);
  }
  if (denominator == _zero) {
    throw const ArgumentException("Denominator cannot be 0.");
  }
  if (numerator == _zero) {
    return BigRational._(_zero, _one);
  }
  return _reduce(numerator, denominator);
}