From dc553f9299b052076f03575853e8cc05154bc06b Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Tue, 24 Apr 2018 21:20:13 -0500 Subject: [PATCH] Implement mod(a,y) --- src/IntervalArithmetic.jl | 1 + src/intervals/functions.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/IntervalArithmetic.jl b/src/IntervalArithmetic.jl index f9e74e604..faaa32e7a 100644 --- a/src/IntervalArithmetic.jl +++ b/src/IntervalArithmetic.jl @@ -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, diff --git a/src/intervals/functions.jl b/src/intervals/functions.jl index e810afc0a..08eaf6ee0 100644 --- a/src/intervals/functions.jl +++ b/src/intervals/functions.jl @@ -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