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

**URL:** <https://discourse.julialang.org/t/how-to-make-a-set-of-real-values-based-on-rtol/11769>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 18, 2018, 11:00pm UTC](https://discourse.julialang.org/t/how-to-make-a-set-of-real-values-based-on-rtol/11769 "2018-06-18T23:00:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [August 6, 2018, 9:59pm UTC](https://discourse.julialang.org/t/how-to-make-a-set-of-real-values-based-on-rtol/11769/3 "2018-08-06T21:59:42Z")

</div>

Or for the simple,

```julia
function filter_approx!(cur_vector; atol=5e-2)
  delete_indices = []

  for (cur_index, cur_value) in enumerate(cur_vector)
    is_duplicate = any(
      tmp_value -> isapprox(tmp_value, cur_value, atol=atol),
      cur_vector[1:cur_index-1]
    )

    is_duplicate || continue
    push!(delete_indices, cur_index)
  end

  deleteat!(cur_vector, delete_indices)

  cur_vector
end

```

* * *

With,

```julia
tmp_vector = [1.0 .+ i * 5e7 * eps() for i in 0:2]
filter_approx!(tmp_vector)

println(tmp_vector)

```

`>> [1.0]`

* * *

Further convenience methods,

```julia
function approx_push!(cur_vector, cur_value; atol=5e-2)
  is_duplicate = any(
    tmp_value -> isapprox(tmp_value, cur_value, atol=atol),
    cur_vector
  )

  is_duplicate && return cur_vector
  push!(cur_vector, cur_value)  
end

```

```julia
function approx_append!(cur_vector, other_vector; atol=5e-2)
  append!(cur_vector, other_vector)  
  filter_approx!(cur_vector; atol=atol)

  cur_vector
end

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-make-a-set-of-real-values-based-on-rtol/11769)._
