-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
float-rational == is not transitive #3102
Comments
I think it's reasonable to restrict |
I agree. We should ensure that == is transitive for all types in Base or we may end up like JavaScript and PHP (where equality isn't even reflexive). It's kind of amazing how difficult it is to make == transitive. There are several intrinsics for int-float comparisons that were fiendishly difficult to concoct. |
I also kind of like the idea of being able to demonstrate that julia> 1/10
0.1
julia> ans == 1//10
false |
This is a fairly insane way to do this, but it works robustly. Even works for Rational{BigInt}, which I really need to add checks for, along with all the other functionality. Temporarily disable some tests in test/numbers.jl until I can sort out what they ought to check, if anything.
Still todo: inequalities. These are always even more of a pain. |
This is a fairly major change, but it's in line with the recent change to make comparisons of floats and rationals strict [#3102]. There is still some work to be done, namely: - handle large values correctly - rational-float inequalities
As I mentioned on the mailing list, I think promotion of (float,rational) to rational is a mistake; it makes the |
Example:
Originally raised here. To fix this, we would have to make comparisons between rationals and floats do something more conservative, such as converting the float to the exact rational value that it represents. For example, this conversion would do it for many Float64s:
However, this does have some problems in that it overflows for floats with large exponents, so something slightly cleverer has to be done to make this work. One also doesn't actually need to construct the rational number to do this comparison – cross multiplication and an equality check will also work.
The text was updated successfully, but these errors were encountered: