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
cos would lead to the functions
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
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
Please let me know what you think, or if you know of any package that does this already.