# [ANN] MultiplesOfPi.jl

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 in the PR that introduced `sinpi` and `cospi`, but I didnâ€™t know of an implementation so I made my own.

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

13 Likes

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.

1 Like

It could be called `MultiplesOfPiâ„Ż`.

9 Likes

Not unrelated, UnitfulAngles.jl.

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