and it is also the actual behavior for some values:
although I suspect pi is a special number type in itself...
Is this intended behavior? It seems more like a bug to me - given a rational and a float I would not expect to be able to express both as rationals, in general (and the floating point precision problems for some rationals just make this silly: try for instance promote(1//3, 0.1) in your REPL...).
// Tomas
Is this intended behavior? It seems more like a bug to me - given a rational and a float I would not expect to be able to express both as rationals, in general (and the floating point precision problems for some rationals just make this silly: try for instance promote(1//3, 0.1) in your REPL...).
julia> promote(1//3, 0.33333333333333333333333333) (1//3,60047990316061//1801498509481984)
julia> promote(0.1,1//10)(3602879701896397//36028797018963968,1//10)
julia> 0.1 - 1//101//180143985094819840julia> float(ans)5.551115123125783e-18
Without this, you can have transitive equality that's consistent with your arithmetic.
OK, that explains a lot.
As a consequence of this change, I guess I'll have to re-write my usage of "promote(x::Real, y::FloatingPoint)..." where x can be either integer or rational (two floats are handled by another method) into something that uses convert instead. How do I make sure that I convert to the correct (i.e. matching) floating point type?
Ok, maybe this change needs to be reconsidered. In that case I suspect that isequal should be transitive (it has to be for hashing to work), while == will not be transitive. We still need some coherent theory of what == means.
On Thursday, June 13, 2013 1:12:20 PM UTC-4, Stefan Karpinski wrote:Ok, maybe this change needs to be reconsidered. In that case I suspect that isequal should be transitive (it has to be for hashing to work), while == will not be transitive. We still need some coherent theory of what == means.
The choice is either:
1) a == b <==> a - b is zero. In this case 1//10 == 0.1, and equality is not transitive. (Note that this rule would imply Inf != Inf, since Inf - Inf -> NaN != 0, whereas IEEE 754 has Inf == Inf, I believe.)
2) a == b means that a and b represent the same numeric value. In this case 1//10 != 0.1 and equality is transitive, but 1//10 - 0.1 == 0.0
Ok, in that case it's just the most recent change that needs to be reverted, not the previous change that made == transitive.
"is approximately equal to" using ~= ?I think exact/inexact is a binary distinction.