# Angle package

**URL:** <https://discourse.julialang.org/t/angle-package/4832>\
**Category:** Community\
**Tags:** package, announcement\
**Created:** [July 13, 2017, 9:55am UTC](https://discourse.julialang.org/t/angle-package/4832 "2017-07-13T09:55:06Z")\
**Posts on this page:** 20\
**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:** [July 13, 2017, 9:55am UTC](https://discourse.julialang.org/t/angle-package/4832/1 "2017-07-13T09:55:06Z")

</div>

Hi community!

Is it a radian? Is it a degree? Who cares! With [`Angles.jl`](https://github.com/yakir12/Angles.jl) you’ll never again need to worry about using `sin` or `sind`.

I built the package we discussed in the previous [discussion](https://discourse.julialang.org/t/should-there-be-a-native-angle-type/4611) about a native angle type. The package is not registered yet because I’m hoping for a major breakthrough in how an `Angle` could automatically inherit all of the functionalities a subtype of `Number` has (see some details about that in this [topic](https://discourse.julialang.org/t/wrap-and-inherit-number/4799/21)).

Please feel free to contribute, file issues, PR, etc. I’d appreciate any input you might have.

Cheers!

Yakir

---

<div class="post-metadata">

**Author:** ![zhangliye](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhangliye/32/3208_2.png) [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Post date:** [July 13, 2017, 10:29am UTC](https://discourse.julialang.org/t/angle-package/4832/2 "2017-07-13T10:29:30Z")

</div>

Very convenient! Thanks!

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 13, 2017, 10:35am UTC](https://discourse.julialang.org/t/angle-package/4832/3 "2017-07-13T10:35:12Z")

</div>

You’re replacing methods defined in `Base` (namely those of inverse trigonometric functions with `Number` input), I think this configures as [type piracy](https://docs.julialang.org/en/stable/manual/style-guide/#Avoid-type-piracy-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:** [July 13, 2017, 10:53am UTC](https://discourse.julialang.org/t/angle-package/4832/4 "2017-07-13T10:53:24Z")

</div>

Oh… how? I didn’t (over)write a `asin` function, I made a new `arcsin` function. Not sure I understand how that is type piracy. Could you explain?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 13, 2017, 11:03am UTC](https://discourse.julialang.org/t/angle-package/4832/5 "2017-07-13T11:03:15Z")

</div>

Oh, sorry, didn’t notice the names were different from those in `Base`. However, the point of the package is to avoid confusion between `sin`/`sind` functions (and that’s fine), but now you’re introducing new inverse functions that does the practically same as functions in `Base`. Isn’t this a contradiction?

---

<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:** [July 13, 2017, 11:05am UTC](https://discourse.julialang.org/t/angle-package/4832/6 "2017-07-13T11:05:17Z")

</div>

Yea, you’re right, but hell if I know how to make `asin` spit a (say) `Radian` _without_ committing type piracy. Let me know if you know how (seriously).

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 13, 2017, 11:13am UTC](https://discourse.julialang.org/t/angle-package/4832/7 "2017-07-13T11:13:50Z")

</div>

Probably I wouldn’t have defined methods for inverse functions 🙂 Or, maybe, extend base methods with an extra argument specifying the return type, that relies, for example, on `asin`/`asind`?

```julia
asin(-0.5, Radian)
asin(sqrt(3)/2, Degree)

```

---

<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:** [July 13, 2017, 12:14pm UTC](https://discourse.julialang.org/t/angle-package/4832/8 "2017-07-13T12:14:40Z")

</div>

“The first argument can be omitted to get the default” is a pretty standard pattern too, eg

```julia
asin(Radian, 0.5)

```

---

<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:** [July 13, 2017, 1:04pm UTC](https://discourse.julialang.org/t/angle-package/4832/9 "2017-07-13T13:04:15Z")

</div>

I like that a lot! Here is the method with the two-argument version:

```julia
julia> using Angles

julia> import Base.asin

julia> asin(::Type{T}, x::Number) where {T <: Angle} = T(Radian(asin(x)))
asin (generic function with 11 methods)

julia> asin(Degree, 0.5)
Angles.Degree{Float64}(30.000000000000004)

```

But how would you define the method for when the first argument is omitted _without_ committing type piracy on the normal version of `asin`?

---

<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:** [July 13, 2017, 1:30pm UTC](https://discourse.julialang.org/t/angle-package/4832/10 "2017-07-13T13:30:51Z")

</div>

> [@yakir12](#):
>
> But how would you define the method for when the first argument is omitted without committing type piracy on the normal version of asin?

I wouldn’t. That’s the point — `Base.asin` is defined, the fallback is radians, no existing code breaks.

---

<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:** [July 13, 2017, 1:33pm UTC](https://discourse.julialang.org/t/angle-package/4832/11 "2017-07-13T13:33:37Z")

</div>

Sorry, I thought you meant there would be a way to call `asin(x)` and get `Radian` back. But the only two options I have is either having a new function with just one argument (e.g. `arcsin(x)`), or the good-old `asin` with two arguments (i.e. `asin(::Type{T}, x)`). Correct?

---

<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:** [July 13, 2017, 1:53pm UTC](https://discourse.julialang.org/t/angle-package/4832/12 "2017-07-13T13:53:10Z")

</div>

I was just suggesting that extending `Base.asin` in with an extra parameter may be a good design choice.

---

<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:** [July 13, 2017, 1:53pm UTC](https://discourse.julialang.org/t/angle-package/4832/13 "2017-07-13T13:53:34Z")

</div>

I understand and agree. Doing it.

---

<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:** [July 13, 2017, 1:59pm UTC](https://discourse.julialang.org/t/angle-package/4832/14 "2017-07-13T13:59:36Z")

</div>

> [@yakir12](#):
>
> how an Angle could automatically inherit all of the functionalities a subtype of Number

Ordinarily, I would expect that `Angle` should be a subtype of `Number`, in the same way that `Unitful.Quantity` is. Also, I’m not sure why you aren’t building this package on top of `Unitful`, which implements a lot of infrastructure to handle units and already has a degree type.

---

<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:** [July 13, 2017, 2:19pm UTC](https://discourse.julialang.org/t/angle-package/4832/15 "2017-07-13T14:19:05Z")

</div>

Agreed, I changed Angle to be a subtype of Number.

My motivations to not building this on top of `Unitful` are:

- This is a learning process for me.
- `Unitful` is big, complete, and works really well in context of other units and dimensions. I love it! But this `Angles` package is really small, doesn’t do much more than keeping the trig functions in check, and is more of a test to see if people would like to have an innate `Angle` type in Julia.
- Are there other entities that are in `Unitful` and should/could get refractured into their own little packages? Are there things in Julia that should be in `Unitful`? Hard to answer, but arguable for sure. I feel that `Angles` falls into one of these grey zones: angles are more widely used than say volumes, and could benefit from their own smaller package.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 13, 2017, 10:44pm UTC](https://discourse.julialang.org/t/angle-package/4832/16 "2017-07-13T22:44:13Z")

</div>

Unless you want to give meaning to a complex angle, the angle should be a real quantity, so `Angle` should be better a subtype of `Real`, rather than `Number`. You’d also replace all occurrences of `Number` with `Real` in the code.

---

<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:** [July 14, 2017, 12:26am UTC](https://discourse.julialang.org/t/angle-package/4832/17 "2017-07-14T00:26:10Z")

</div>

> [@giordano](#):
>
> Unless you want to give meaning to a complex angle

Perfectly meaningful…what do you think `asin(1.2+0im)` is?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 14, 2017, 5:28am UTC](https://discourse.julialang.org/t/angle-package/4832/18 "2017-07-14T05:28:49Z")

</div>

> [@stevengj](#):
>
> Perfectly meaningful…what do you think `asin(1.2+0im)` is?

The extension to complex plane of a well defined _mathematical_ function. I mean, is there a _physical_ meaning of “`1.2 + 3.4im` radians/degrees”? `deg2rad` and `rad2deg` aren’t defined for complex input in Julia (for the record, they should be in Matlab). The package seems more oriented to handle conversion between _physical_ angles with different units.

---

<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:** [July 14, 2017, 7:25am UTC](https://discourse.julialang.org/t/angle-package/4832/19 "2017-07-14T07:25:28Z")

</div>

Or I could just keep it as a subtype of `Number`, extending the functionality of the package to include angles with imaginary numbers and not losing any of its performance (I think…).

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 14, 2017, 8:34am UTC](https://discourse.julialang.org/t/angle-package/4832/20 "2017-07-14T08:34:03Z")

</div>

> [@yakir12](#):
>
> Or I could just keep it as a subtype of Number, extending the functionality of the package to include angles with imaginary numbers and not losing any of its performance (I think…).

Sorry, I don’t get what you mean.

My point is that, as far as I know, there is no such thing like “complex angle”. There are complex numbers to which trigonometric functions can be applied, but I couldn’t find an interpretation of these numbers as _geometrical_ or _physical_ angles. I thought about solid angles, that are two-dimensional angles, but it doesn’t seem that complex numbers are used to represent in any way solid angles.

[Next page](https://discourse.julialang.org/t/angle-package/4832.md?page=2)
