Open mbravenboer opened 3 years ago
This is definitely intentional, although it might deserve a better error message. Note that the corresponding floating point computation 0.0 * Inf
also returns NaN
, not 0.0
. We could technically allow 0 // 0
as the equivalent of NaN
for Rational
, but silent NaN
s often cause more problems than they solve, so I don't really think we want to do this.
Thanks for the background @simeonschaub .
We were generally hoping that the Rational
type would have more of the desirable mathematical properties, like associativity, 0 * x = x
etc (modulo overflow). If that is a goal of the Rational
type (maybe it is not), then the binary floating-point standard is maybe not a good reference?
That's generally not something that's possible in a consistent way if you decide to include +/- infinity as well. In practice, I would think that you can often just ignore the existence of these infinities or explicitly check against them.
0 * Inf = 0 definitely seems like bad math. Consider $\lim{x\rightarrow 0} x/x$; the answer is of course 1, not zero. But of course $\lim{x\rightarrow 0} 2x/x = 2$. So it's not an operation you can define meaningfully, so either the error or a NaN-equivalent is perfect.
I see, yeah I realize that in our system maybe the problem is that infinity should not have been allowed to begin with. The Rational type chooses to support infinity as a special value, but I probably didn't want that. The mathematical properties I had in mind seem okay if you exclude infinity.
The problem is that the gcd is 0 with
x.num
andy.den
both being0
For any
x
, I think an appropriate value for0 * x
would be 0?