floor method
Returns the floor of the BigRational as a BigRational with denominator 1
Implementation
BigRational floor() {
BigInt flooredNumerator;
if (numerator.isNegative && denominator.isNegative) {
// Both numerator and denominator are negative: treat as positive
flooredNumerator = numerator.abs() ~/ denominator.abs();
} else if (numerator.isNegative || denominator.isNegative) {
// One of them is negative: result will be negative
flooredNumerator =
(numerator.abs() ~/ denominator.abs()) * BigInt.from(-1) - BigInt.one;
} else {
// Both are positive: simple integer division
flooredNumerator = numerator ~/ denominator;
}
// Return the floored value as a BigRational with denominator 1
return BigRational(flooredNumerator, denominator: BigInt.one);
}