Skip to content

Commit 7f233b2

Browse files
Luis Benetdpsanders
authored andcommitted
Implement mod(a,y)
1 parent 777ad9d commit 7f233b2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/IntervalArithmetic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Base:
1515
in, zero, one, eps, typemin, typemax, abs, abs2, real, min, max,
1616
sqrt, exp, log, sin, cos, tan, inv,
1717
exp2, exp10, log2, log10,
18+
mod,
1819
asin, acos, atan, atan2,
1920
sinh, cosh, tanh, asinh, acosh, atanh,
2021
union, intersect, isempty,

src/intervals/functions.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,23 @@ for f in (:log, :log2, :log10, :log1p)
266266

267267
end
268268
end
269+
270+
# mod
271+
function mod(a::Interval, y::T) where {T<:Real}
272+
yy = abs(y)
273+
fld_lo = fld(a.lo, yy)
274+
fld_hi = fld(a.hi, yy)
275+
z = zero(fld_lo)
276+
277+
if fld_lo != fld_hi
278+
# `a` includes a discontinuity of `mod`
279+
if y > 0
280+
return interval(z, y)
281+
else
282+
return interval(y, z)
283+
end
284+
else
285+
# no discontinuity crossed within `a`
286+
return interval(mod(a.lo, y), mod(a.hi, y))
287+
end
288+
end

0 commit comments

Comments
 (0)