Skip to content

Commit 766bef9

Browse files
yashrajguptadpsanders
authored andcommitted
Add sinpi and cospi function (#284)
1 parent 7b123cd commit 766bef9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/IntervalArithmetic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Base:
2424
sqrt, exp, log, sin, cos, tan, inv,
2525
exp2, exp10, log2, log10,
2626
asin, acos, atan,
27-
sinh, cosh, tanh, asinh, acosh, atanh,
27+
sinh, cosh, tanh, asinh, acosh, atanh, sinpi, cospi,
2828
union, intersect, isempty,
2929
convert, promote_rule, eltype, size,
3030
BigFloat, float, widen, big,

src/intervals/trigonometric.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ function sin(a::Interval{Float64})
137137
end
138138
end
139139

140+
function sinpi(a::Interval{T}) where T
141+
isempty(a) && return a
142+
w = a * pi_interval(T)
143+
return(sin(w))
144+
end
140145

141146
function cos(a::Interval{T}) where T
142147
isempty(a) && return a
@@ -222,6 +227,11 @@ function cos(a::Interval{Float64})
222227
end
223228
end
224229

230+
function cospi(a::Interval{T}) where T
231+
isempty(a) && return a
232+
w = a * pi_interval(T)
233+
return(cos(w))
234+
end
225235

226236
function find_quadrants_tan(x::T) where {T}
227237
temp = atomic(Interval{T}, x) / half_pi(x)

test/interval_tests/trig.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ end
4040
@test cos(@biginterval(1.3, 6.3)) cos(@interval(1.3, 6.3))
4141
end
4242

43+
@testset "sinpi" begin
44+
@test sinpi(∅) ==
45+
@test sinpi(0.5 .. 1.5) == Interval(-1 , 1)
46+
@test sinpi(1 .. 2) Interval(-1 , 0)
47+
@test sinpi(0.25 .. 0.75) Interval(1/sqrt(2) , 1)
48+
@test sinpi(-0.25 .. 0.25) Interval(-1/sqrt(2) , 1/sqrt(2))
49+
end
50+
51+
@testset "cospi" begin
52+
@test cospi(∅) ==
53+
@test cospi(1 .. 2) == Interval(-1 , 1)
54+
@test cospi(0.5 .. 1.5) Interval(-1 , 0)
55+
@test cospi(0.25 .. 0.75) Interval(-1/sqrt(2) , 1/sqrt(2))
56+
@test cospi(-0.25 .. 0.25) == Interval(1/sqrt(2) , 1)
57+
end
58+
4359
@testset "tan" begin
4460
@test tan(@interval(0.5)) == Interval(0.54630248984379048, 0.5463024898437906)
4561
@test tan(@interval(0.5, 1.67)) == entireinterval()

0 commit comments

Comments
 (0)