Skip to content

Commit

Permalink
More WIP to correct tan
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders committed Apr 11, 2018
1 parent 5f1e3ae commit bce6101
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions src/intervals/trigonometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function find_quadrants(x::T) where {T}
end

function find_quadrants(x::Float64)
temp = multiply_by_positive_constant(x, one_over_half_pi_interval)
# x / half_pi(Float64)
# temp = multiply_by_positive_constant(x, one_over_half_pi_interval)
temp = x / half_pi(Float64)

return SVector(floor(temp.lo), floor(temp.hi))
end
Expand Down Expand Up @@ -131,58 +131,56 @@ function cos(a::Interval{T}) where T
end
end

"""Fix endpoints in correct quadrant
function tan(a::Interval{T}) where T
isempty(a) && return a

diam(a) > pi_interval(T).lo && return entireinterval(a)
This is necessary only for tan (not sin or cos), since sin and cos
are flat near the quadrant boundaries.
"""

lo_quadrants = find_quadrants(a.lo)
function fix_quadrant(a, x::T) where T
quadrants = find_quadrants(x)

if lo_quadrants[1] == lo_quadrants[2] # unambiguous quadrant
lo_quadrant = lo_quadrants[1]
if quadrants[1] == quadrants[2] # unambiguous quadrant
quadrant = quadrants[1]

else # check if end-point is really in the other quadrant
if lo_quadrants[2] * half_pi(T) a
lo_quadrant = lo_quadrants[1]
if quadrants[2] * half_pi(T) a
quadrant = quadrants[2]

else
lo_quadrant = lo_quadrants[2]
quadrant = quadrants[1]
end

end

hi_quadrants = find_quadrants(a.hi)
return quadrant
end

if hi_quadrants[1] == hi_quadrants[2]
hi_quadrant = hi_quadrants[1]

else # check if end-point is really in the other quadrant
if hi_quadrants[2] * half_pi(T) a
hi_quadrant = hi_quadrants[2]
function tan(a::Interval{T}) where T
isempty(a) && return a

else
hi_quadrant = hi_quadrants[1]
end
diam(a) > pi_interval(T).lo && return entireinterval(a)

end
lo_quadrant = fix_quadrant(a, a.lo)
hi_quadrant = fix_quadrant(a, a.hi)

lo_quadrant_mod = mod(lo_quadrant, 2)
hi_quadrant_mod = mod(hi_quadrant, 2)
#hi_quadrant_mod = mod(hi_quadrant, 2)

if lo_quadrant_mod == 0 && hi_quadrant_mod == 1
return entireinterval(a) # crosses singularity

elseif lo_quadrant_mod == hi_quadrant_mod && hi_quadrant > lo_quadrant
# must cross singularity
return entireinterval(a)
if lo_quadrant == hi_quadrant
return @round(tan(a.lo), tan(a.hi))

elseif hi_quadrant - lo_quadrant == 1
if lo_quadrant_mod == 1
return @round(tan(a.lo), tan(a.hi))
else
return entireinterval(a) # crosses singularity
end
end

# @show a.lo, a.hi
# @show tan(a.lo), tan(a.hi)
return entireinterval(a)

return @round(tan(a.lo), tan(a.hi))
end

function asin(a::Interval{T}) where T
Expand Down

0 comments on commit bce6101

Please sign in to comment.