How to make a Set of real values based on rtol?

Set is based on hashing, and there won’t be a hash function for your notion of equality, because it’s not transitive.

julia> a,b,c = [1.0 .+ i * 5e7 * eps() for i in 0:2];

julia> isapprox(a,b)
true

julia> isapprox(b,c)
true

julia> isapprox(a,c)
false

Because you want to do this for real numbers, which are ordered, you should be able to keep a sorted list of members. That way, it will take log(n) time to insert an element or decide it’s already inserted, instead of n time. You should be able to use searchsorted for this.

4 Likes