# Complex{Float64} \<: Complex{Real} is false. Intended or potential inconsistency?

**URL:** <https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 24, 2018, 8:41pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956 "2018-11-24T20:41:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![merement](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/merement/32/7059_2.png) [@merement](https://discourse.julialang.org/u/merement)\
**Post date:** [November 24, 2018, 8:41pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/1 "2018-11-24T20:41:48Z")

</div>

On Julia 1.0.2

```
julia> Float64 <: Real
true

```

as it should be but

```
julia> Complex{Float64} <: Complex{Real}
false

```

Mathematically speaking, this should be true as well but, I guess, Julia has to deal with types of a more general nature, which probably makes it difficult to determine whether one composite type is a subset (or what is the correct term for such things) of another type.

If the current behavior is intended, how to implement type assertion in situations like

```
function foo(z::Complex{Real})
    return sqrt(z)
end

```

to make sure that both `foo(0.0im)` and `foo(0im)` work in the same way as for `z::Real` with `foo(0.0)` and `foo(0)`?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 24, 2018, 8:44pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/2 "2018-11-24T20:44:23Z")

</div>

You need `Complex{<:Real}`. That’s due to type invariance, while what you want is covariance (look for these keywords in the manual).

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [November 24, 2018, 9:01pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/3 "2018-11-24T21:01:08Z")

</div>

I have wondered why Julia has this limitation. Is it for performance or just to reduce complexity?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [November 24, 2018, 9:10pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/4 "2018-11-24T21:10:08Z")

</div>

It’s not a limitation, its a property. It’s deeply related to everything in the language and basically everything has to be done differently if you change this so it’s hard to say what exactly it is for.

Of course someone might be able to comment on the original reason this is selected, though finding an alternative for that particular reason will not be enough to make such change at this point.

---

<div class="post-metadata">

**Author:** ![merement](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/merement/32/7059_2.png) [@merement](https://discourse.julialang.org/u/merement)\
**Post date:** [November 24, 2018, 9:11pm UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/5 "2018-11-24T21:11:38Z")

</div>

Thanks a bunch! It looks like, indeed, I needed type covariance all the way and just coincidentally didn’t run into the same problem before. The funny part is I did read that part in the manual and it made sense but somehow syntactic details didn’t register.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 25, 2018, 12:45am UTC](https://discourse.julialang.org/t/complex-float64-complex-real-is-false-intended-or-potential-inconsistency/17956/6 "2018-11-25T00:45:57Z")

</div>

> [@xiaodai](#):
>
> I have wondered why Julia has this limitation. Is it for performance or just to reduce complexity?

It’s absolutely critical for performance, [as I explained in another post.](https://discourse.julialang.org/t/problem-with-complex-rationals/9474/7)
