Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I'm trying to create a mathematical operation that help me to resolve this scenario.

I have a list of "limits" as show below:

0---4---8---12... (n + 4)

Suppose that we have a software that "read" a number, an it determines what is the previous "step limit". For example:

Given | Previous limit step
3     | 1 (the limit would be 0)
4     | 2 (the limit would be 4)
7     | 2 (the limit would be 4)
9     | 3 (the limit would be 8)

What I need to do is trying to get the previous limit in question, as show below:

Given | Previous limit
3     | 0
4     | 4
7     | 4
9     | 8

I have two days dealing with a formula to get it, but no good results.

share|improve this question
I feel so stupid.. viewing the results as table I think that the formula is limit = 4(n-1) –  manix Oct 12 '12 at 18:16

1 Answer 1

up vote 1 down vote accepted

$x - (x \text{ mod } 4)$ should be what you are looking for. $\text{a mod b}$ returns the remainder of $a$ divided by $b$, i.e. what remains of $a$ if you subtract $b$ is many times as possible without making the result negative. In a of programming languages, operator "%" means $\text{mod}$, so you'd write x - (x % 4) to compute your "previous limit".

share|improve this answer
You are correct –  manix Oct 13 '12 at 6:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.