# Why not cossin?

**URL:** <https://discourse.julialang.org/t/why-not-cossin/24484>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [May 22, 2019, 3:51pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484 "2019-05-22T15:51:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 22, 2019, 3:51pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/1 "2019-05-22T15:51:48Z")

</div>

We have `sincos`, why not `cossin`? I have no idea why `sincos` is here and not `cossin` (perhaps because of the “awkward” `ss` in the name…), but for me the convention of `xy` in a 2D coordinate means that calculating a new coordinate from a known point, angle, and distance is awkward with a `sincos` function:

```julia
xy = SVector(1.0,2.0)
α = π/2
l = 1
xy2 = xy + l*SVector(sincos(α))[2:-1:1] # note the reordering of the elements

```

Maybe you have an explanation or a better solution?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 22, 2019, 4:01pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/2 "2019-05-22T16:01:44Z")

</div>

Do you need

```julia
reverse(sincos(x))

```

?

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 22, 2019, 4:04pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/3 "2019-05-22T16:04:07Z")

</div>

Sure! I just read about it, or the Iterators.reverse version without the copy. Cool.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 22, 2019, 4:07pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/4 "2019-05-22T16:07:05Z")

</div>

> [@yakir12](#):
>
> or the Iterators.reverse version without the copy

I don’t think there is a copy (if the compiler can infer things, eg inside a function), as `sincos` returns a tuple.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 22, 2019, 4:08pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/5 "2019-05-22T16:08:54Z")

</div>

🤷‍♂️

```julia
reverse(v [, start=1 [, stop=length(v)]] )

  **Return a copy of v** reversed from start to stop. See also Iterators.reverse for reverse-order
  iteration without making a copy.

```

---

<div class="post-metadata">

**Author:** ![piever](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piever/32/1815_2.png) [@piever](https://discourse.julialang.org/u/piever)\
**Post date:** [May 22, 2019, 4:14pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/6 "2019-05-22T16:14:42Z")

</div>

I think that docstring refers to the method where `v` is an array. As a rule of thumb, you can often create tuples of isbits types without allocations:

```julia
julia> @allocated reverse(sincos(1))
0

julia> @allocated collect(sincos(1)) #creating the vector would allocate
96

```

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 22, 2019, 4:16pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/7 "2019-05-22T16:16:55Z")

</div>

Well, in that case `cossin` _is_ `reverse(sincos)`, cool!

---

<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:** [May 22, 2019, 4:17pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/8 "2019-05-22T16:17:08Z")

</div>

Depending on the interpretation there is a copy. It just doesn’t matter. Fwiw, by that interpretation it’s almost for sure that the iterator version is also making a copy.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 22, 2019, 4:40pm UTC](https://discourse.julialang.org/t/why-not-cossin/24484/9 "2019-05-22T16:40:11Z")

</div>

Sure, technically it is a copy in the sense that it does not share modifiable structure with the argument. But for tuples that is always true.

What happens here should be equivalent to

```julia
x, y = sincos(r)
y, x

```
