Skip to content

Commit

Permalink
Implement mod(a,y)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luis Benet committed Jun 24, 2018
1 parent b7163bd commit dc553f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/IntervalArithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Base:
in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
sqrt, exp, log, sin, cos, tan, inv,
exp2, exp10, log2, log10,
mod,
asin, acos, atan, atan2,
sinh, cosh, tanh, asinh, acosh, atanh,
union, intersect, isempty,
Expand Down
20 changes: 20 additions & 0 deletions src/intervals/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,23 @@ for f in (:log, :log2, :log10, :log1p)

end
end

# mod
function mod(a::Interval, y::T) where {T<:Real}
yy = abs(y)
fld_lo = fld(a.lo, yy)
fld_hi = fld(a.hi, yy)
z = zero(fld_lo)

if fld_lo != fld_hi
# `a` includes a discontinuity of `mod`
if y > 0
return interval(z, y)
else
return interval(y, z)
end
else
# no discontinuity crossed within `a`
return interval(mod(a.lo, y), mod(a.hi, y))
end
end

0 comments on commit dc553f9

Please sign in to comment.