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.