I'm trying to find the maximum and minimum attained value of $$\text{mod}(x, y) = x-y\left\lfloor\frac{x}{y}\right\rfloor$$ where $x$ belongs to an integer range $[a, b]$ and $y$ belongs to an integer range $[c, d]\setminus\{0\}$. I am aware that this is the remainder of division of $x$ and $y$, and yes, $x$ and $y$ are integers so they can be negative.
So, for a set $y$ the problem becomes pretty simple as all you need to do is identify when the discontinuity in the function lies within the integer range $[a, b]$, then it takes the global min/max and otherwise just the values at the endpoints.
So far I've tried to identify ranges of $y$ which also helps reduce the problem in this way but it seems as if it is extremely complex. One inequality that can guarantee the discontinuity is in the integer range for any $y$ is: $$y\left\lfloor\frac{b}{y}\right\rfloor > a$$ However the actual regions where this is true look extremely complicated and I'm struggling to go any further from here.
In terms of a solution, an algorithm or just straight up a numerical answer is what I'm looking for. (Aside from the obvious algorithm of applying the fixed $y$ for every integer in $[c, d]\setminus\{0\}$)