Skip to content

Commit 3dae25f

Browse files
committed
Add exact results for trig fcns on π
Since Julia has already gone to the trouble to encode π exactly, and trig functions are defined in terms of π, they should give exact answers for this particular constant.
1 parent 17e0bba commit 3dae25f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

base/mathconstants.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,10 @@ Base.literal_pow(::typeof(^), ::Irrational{:ℯ}, ::Val{p}) where {p} = exp(p)
123123
Base.log(::Irrational{:ℯ}) = 1 # use 1 to correctly promote expressions like log(x)/log(ℯ)
124124
Base.log(::Irrational{:ℯ}, x::Number) = log(x)
125125

126+
Base.sin(::Irrational{:π}) = 0.0
127+
Base.cos(::Irrational{:π}) = -1.0
128+
Base.sincos(::Irrational{:π}) = (0.0, -1.0)
129+
Base.tan(::Irrational{:π}) = 0.0
130+
Base.cot(::Irrational{:π}) = -1/0
131+
126132
end # module

base/special/exp.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ See also [`exp2`](@ref), [`exp10`](@ref) and [`cis`](@ref).
333333
julia> exp(1.0)
334334
2.718281828459045
335335
336-
julia> exp(im * pi) == cis(pi)
336+
julia> exp(im * pi) cis(pi)
337337
true
338338
```
339339
""" exp(x::Real)

test/math.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ end
5353
@test occursin("3.14159", sprint(show, MIME"text/plain"(), π))
5454
@test repr(Any[pi ℯ; ℯ pi]) == "Any[π ℯ; ℯ π]"
5555
@test string(pi) == "π"
56+
57+
@test sin(π) === sinpi(1) == tan(π) == sinpi(1 // 1) == 0
58+
@test cos(π) === cospi(1) == sec(π) == cospi(1 // 1) == -1
59+
@test csc(π) == 1/0 && cot(π) == -1/0
60+
@test sincos(π) === sincospi(1) == (0, -1)
5661
end
5762

5863
@testset "frexp,ldexp,significand,exponent" begin

0 commit comments

Comments
 (0)