operator / method
Returns the quotient of this Number divided by the divisor (a Number or num).
This Number is unaffected.
Implementation
@override
Number operator /(dynamic divisor) {
if (divisor is num) {
if (divisor.isNaN) return Double.NaN;
if (divisor == 0) {
return value == 0
? Double.NaN
: value > 0
? Double.infinity
: Double.negInfinity;
}
final num quotient = value / divisor;
return quotient.toInt() == quotient
? Integer(quotient.toInt())
: Double(quotient.toDouble());
}
if (divisor is Precise) return (Precise.num(value)) / divisor;
if (divisor is Real) {
if (divisor.isNaN) return Double.NaN;
if (divisor.value == 0) {
return value == 0
? Double.NaN
: value > 0
? Double.infinity
: Double.negInfinity;
}
final num quotient = value / divisor.value;
return quotient.toInt() == quotient
? Integer(quotient.toInt())
: Double(quotient.toDouble());
}
if (divisor is Complex) {
// (a + 0i) / (c + di) = (ac - adi) / (c^2 + d^2)
if (divisor.real.isNaN || divisor.imag.value.isNaN) return Double.NaN;
final c2d2 = (divisor.real ^ 2.0) + (divisor.imaginary.value ^ 2.0);
final aOverc2d2 = this / c2d2;
return Complex(aOverc2d2 * divisor.real as Real,
Imaginary(aOverc2d2 * divisor.imaginary.value * -1.0));
}
if (divisor is Imaginary) {
if (divisor.value.isNaN) return Imaginary(Double.NaN);
if (value == 0 && divisor.value.value == 0) return Imaginary(Double.NaN);
return Imaginary(-this / divisor.value);
}
// Treat divisor as 0.
return value > 0 ? Double.infinity : Double.negInfinity;
}