# Questions related to -0.0 and 0.0

**URL:** https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158
**Category:** General Usage
**Tags:** question
**Created:** [October 21, 2021, 2:55pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158 "2021-10-21T14:55:11Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 21, 2021, 2:55pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/1 "2021-10-21T14:55:11Z")

</div>

I’m using PCHIPInterpolation to do some interpolation.  
`itp = Interpolator(xs, ys);`

This program absolutely does not allow any values in its x to be duplicates. I now have some values like the below in my data sets:  
`xs = [-5.0, -0.0, 0.0, 10.0, 19.0];`

The interpolation would stop and give an error: “xs must be stricly increasing”. I tried to fix this issue by first using the unique function, but unique actually think they are different.

Is there a better way to address this issue?

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [October 21, 2021, 2:56pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/2 "2021-10-21T14:56:41Z")

</div>

See [Is this a bug of the Julia function "unique"? - #30 by giordano](https://discourse.julialang.org/t/is-this-a-bug-of-the-julia-function-unique/70141/30) The next patch release of 1.6, and 1.7.0 will both fix this.

TLDR is that `unique` currently and incorrectly uses `==` instead of `isequal`

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 21, 2021, 2:58pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/3 "2021-10-21T14:58:44Z")

</div>

Thanks, Oscar. I started the other thread too 🙂

I’m just hoping to find an alternative solution to address the issue, so that I don’t have to wait for the next version of Julia before I can process my data.

For the NaN issue. I have decided to fill it up with some identical numerical values to get it working.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [October 21, 2021, 3:03pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/4 "2021-10-21T15:03:58Z")

</div>

you could always perform minor type piracy and redefine `Base.unique` to do the thing it will do as of the next release. It’s not a great solution, but it will work.

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [October 21, 2021, 3:04pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/5 "2021-10-21T15:04:55Z")

</div>

julia\> xs = [-5.0, -0.0, 0.0, 10.0, 19.0];

julia\> unique(t → t == 0 ? 0.0 : t, xs)  
4-element Vector{Float64}:  
-5.0  
-0.0  
10.0  
19.0

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 21, 2021, 3:08pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/6 "2021-10-21T15:08:15Z")

</div>

Thanks. Unfortunately, I got the below error when testing:

```julia
UndefVarError: t not defined
Stacktrace:
 [1] top-level scope
   @ In[129]:3
 [2] eval
   @ ./boot.jl:360 [inlined]
 [3] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1116

```

> [@GunnarFarneback](#):
>
> xs = [-5.0, -0.0, 0.0, 10.0, 19.0];
> 
> julia\> unique(t → t == 0 ? 0.0 : t, xs)

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 21, 2021, 3:09pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/7 "2021-10-21T15:09:41Z")

</div>

No need to wait, you can just use the 1.7 release candidate

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [October 21, 2021, 3:11pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/8 "2021-10-21T15:11:09Z")

</div>

> [@GunnarFarneback](#):
>
> julia\> unique(t → t == 0 ? 0.0 : t, xs)

I think the JuliaMono font fooled my copy and paste. That arrow really should be `->`.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [October 21, 2021, 3:21pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/9 "2021-10-21T15:21:17Z")

</div>

> [@Oscar\_Smith](#):
>
> See [Is this a bug of the Julia function “unique”? - #29 by leon](https://discourse.julialang.org/t/is-this-a-bug-of-the-julia-function-unique/70141/30) The next patch release of 1.6, and 1.7.0 will both fix this.
> 
> TLDR is that `unique` currently and incorrectly uses `==` instead of `isequal`

I don’t think that will solve @leon’s problem? Since `isequal(0.0, -0.0) == false` the values returned by `unique` will still include 0.0 and -0.0…

Actually if `unique` is currently using `==` I don’t understand why both are included in the result, since

```julia
julia> 0.0 == -0.0
true

```

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 21, 2021, 3:53pm UTC](https://discourse.julialang.org/t/questions-related-to-0-0-and-0-0/70158/10 "2021-10-21T15:53:48Z")

</div>

It is working now! Thank you so much.

BTW, is there a way I can find the index of the elements that remained? I have another set of data y that goes with the x.

Ind = …  
y = y[Ind];

> [@GunnarFarneback](#):
>
> unique(t → t == 0 ? 0.0 : t, xs)
