# \[ANN\] MultiplesOfPi.jl

**URL:** https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690
**Category:** Package Announcements
**Tags:** package, announcement
**Created:** [March 7, 2020, 3:15pm UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690 "2020-03-07T15:15:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [March 7, 2020, 3:15pm UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/1 "2020-03-07T15:15:55Z")

</div>

Hi everyone!

This is a small package to solve a specific problem: to avoid floating-point errors while using multiples of pi in arithmetic or trigonometric functions. The package exports the constant `Pi` that is numerically equivalent to `pi`, except it delays the conversion to float. Using `Pi`, or a multiple of it, as an argument to trigonometric functions such as `sin` and `cos` would lead to the functions `sinpi` and `cospi` being used under the hood, so the result might end up being exact.

This can help, for example, in obtaining exact results such as

```
julia> (1//3)pi + (4//3)pi == (5//3)pi
false

julia> (1//3)Pi + (4//3)Pi == (5//3)Pi
true

# Euler's identity
julia> exp(im*pi) + 1 == 0
false

julia> exp(im*Pi) + 1 == 0
true

```

The concept is not unknown to the community, in fact it was [discussed in 2013](https://github.com/JuliaLang/julia/pull/4112#issuecomment-22961778) in the PR that introduced `sinpi` and `cospi`, but I didn’t know of an implementation so I made my own.

Github: [GitHub - jishnub/MultiplesOfPi.jl: Numbers that produce accurate results when used as arguments to trigonometric functions](https://github.com/jishnub/MultiplesOfPi.jl.git)

Please let me know what you think, or if you know of any package that does this already.

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [March 7, 2020, 10:19pm UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/2 "2020-03-07T22:19:59Z")

</div>

Would it make sense to have a slightly more general package that also involved `ℯ`? (I guess more transendentals could be added too though I’d imagine there’s only a few for which this would be quite useful)

Edit: come to think of it, maybe the package is great just as it is: a nicely wrapped up functionality, clean and simple.

---

<div class="post-metadata">

### Author: ![yurivish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yurivish/32/307_2.png) [@yurivish](https://discourse.julialang.org/u/yurivish)
#### Post date: [March 7, 2020, 10:44pm UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/3 "2020-03-07T22:44:08Z")

</div>

It could be called `MultiplesOfPiℯ`.

---

<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: [March 8, 2020, 6:58am UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/4 "2020-03-08T06:58:21Z")

</div>

Not unrelated, UnitfulAngles.jl.

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [March 8, 2020, 7:11am UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/5 "2020-03-08T07:11:19Z")

</div>

Thanks, this is indeed related, and I’ll add a link to this in the Readme.

---

<div class="post-metadata">

### Author: ![dlfivefifty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlfivefifty/32/1959_2.png) [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)
#### Post date: [March 8, 2020, 10:08am UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/6 "2020-03-08T10:08:40Z")

</div>

At that point just make a `ScaledIrrational` type that can do any constant

---

<div class="post-metadata">

### Author: ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)
#### Post date: [March 8, 2020, 10:25am UTC](https://discourse.julialang.org/t/ann-multiplesofpi-jl/35690/7 "2020-03-08T10:25:36Z")

</div>

I do like the idea of pi being just a “unit” same goes for euler’s constant. Often in, hairy equations it cancels as a quantity anyways. But, many people also want that irrational approximate numeric result. Hm.
