# Complex Number Arrays

**URL:** https://discourse.julialang.org/t/complex-number-arrays/4393
**Category:** General Usage
**Tags:** question, embedding, complex-numbers
**Created:** [June 21, 2017, 7:16pm UTC](https://discourse.julialang.org/t/complex-number-arrays/4393 "2017-06-21T19:16:07Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)
#### Post date: [June 21, 2017, 7:16pm UTC](https://discourse.julialang.org/t/complex-number-arrays/4393/1 "2017-06-21T19:16:07Z")

</div>

I can’t seem to find the struct for a complex number representation in Julia Embedding in C API.  
Thank you.

---

<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: [June 21, 2017, 10:42pm UTC](https://discourse.julialang.org/t/complex-number-arrays/4393/2 "2017-06-21T22:42:22Z")

</div>

`Complex` is essentially the same as complex numbers in C or C++: it is the [real part followed by the imaginary part](https://github.com/JuliaLang/julia/blob/8915d9b3384d5ffbafeb83974c267d983f4cb07d/base/complex.jl#L3-L14). So, for example, `Complex{Float64}` is the same in-memory format as the C99 `double complex` and the C++ `std::complex<double>`.

---

<div class="post-metadata">

### Author: ![tastelessjolt](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@tastelessjolt](https://discourse.julialang.org/u/tastelessjolt)
#### Post date: [June 23, 2017, 5:32pm UTC](https://discourse.julialang.org/t/complex-number-arrays/4393/3 "2017-06-23T17:32:14Z")

</div>

Thank you for your reply. So, it’s the same the STL’s complex number. So, now how do I create `Complex{Float64}` type using C API? Like for an `Array{Float64}`, I call `jl_apply_array_type(jl_float64_type, ndims)` and use that to initialise the variable. I see a `jl_complex_type` but I don’t know how to specify which type of variable it stores.

EDIT:  
I found the way to do it,

```julia
jl_value_t *type = (jl_value_t*) jl_apply_type((jl_value_t*)jl_complex_type, jl_svec1(jl_float64_type));
            
jl_value_t *ret = (jl_value_t*)jl_new_struct_uninit(type);
double complex *temp = (double complex*) ret;
*temp = data + (img_data * I);

```

Thank you.
