I've got an application where Set semantics would be useful for me, but I'm dealing with floating point numbers. I'd like to have a criterion for inclusion in the set that isn't exact equality - that is, if my Set already contains 0.5, I'd like it to ignore 0.50000000000000000018 if there's an attempt to add it. Is there existing machinery that allows this?
As long as you don't need to keep the precision up in the Set, you could use a Set{Float16} or Set{Float32}:
julia> set = Set{Float16}()
Set{Float16}()
julia> push!(set, Float16(2.3))
Set{Float16} with 1 element:
Float16(2.3)
julia> push!(set, Float16(2.300000001))
Set{Float16} with 1 element:
Float16(2.3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With