Skip to content

Commit

Permalink
fixed one to get sec and csc working
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 3, 2020
1 parent 083f797 commit d5c4bb1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/MultiplesOfPi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ Base.:(*)(y::Real,p1::PiTimes) = PiTimes(p1.x*y)
Base.:(*)(p1::PiTimes,p2::PiTimes) = float(p1) * float(p2)
Base.:(*)(z::Complex{Bool},p::PiTimes) = p*z # switch the orders to get to something that's non-ambiguous

Base.one(::Type{PiTimes{T}}) where {T} = one(T)

end # module
38 changes: 28 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ using Test
@test PiTimes(2) == PiTimes(2)
end
end
@testset "one" begin
@test one(PiTimes{Int}) == one(Int)
@test one(PiTimes{Float64}) == one(Float64)
@test one(PiTimes{BigFloat}) == one(BigFloat)
end
@testset "conversion" begin
@test convert(Float64,PiTimes(1)) Float64(1π)
@test Float64(PiTimes(1)) Float64(1)*π
Expand Down Expand Up @@ -72,23 +77,36 @@ using Test
end
end
@testset "trigonometric functions" begin
x = 1.5
@test sin(PiTimes(x)) == sinpi(x) sin*x)
x = 1
@test cos(PiTimes(x)) == cospi(x) cos*x)
x = 1.1
@test cis(PiTimes(x)) == cospi(x) + im*sinpi(x) cos*x) + im*sin*x)
@testset "sin and cos" begin
x = 1.5
@test sin(PiTimes(x)) == sinpi(x) == -1 sin*x)
x = 1
@test cos(PiTimes(x)) == cospi(x) == -1 cos*x)

a = sincos(PiTimes(x))
@test a[1] == sinpi(x)
@test a[2] == cospi(x)
end

a = sincos(PiTimes(x))
@test a[1] == sinpi(x)
@test a[2] == cospi(x)
@testset "complex exp" begin
x = 1.1
@test cis(PiTimes(x)) == cospi(x) + im*sinpi(x) cos*x) + im*sin*x)

@testset "exp" begin
@test exp(im*PiTimes(0)) == cis(PiTimes(0)) == 1
@test exp(im*PiTimes(1/2)) == cis(PiTimes(1/2)) == im
@test exp(im*PiTimes(1)) == cis(PiTimes(1))== -1
@test exp(im*PiTimes(3/2)) == cis(PiTimes(3/2)) == -im
end

@testset "sec and csc" begin
@test sec(PiTimes(1)) == -1
@test sec(PiTimes(2)) == 1
@test !isfinite(sec(PiTimes(1/2)))

@test csc(PiTimes(1/2)) == 1
@test csc(PiTimes(3/2)) == -1
@test !isfinite(csc(PiTimes(1)))
end
end
@testset "hyperbolic" begin
@testset "cosh" begin
Expand Down

0 comments on commit d5c4bb1

Please sign in to comment.