0

How do I to determine, given pairs $\{m_1, M_1\}$ and $\{m_2, M_2\}$, where $m_n \le 0$, $M_n \gt 0$ and $\{m_n, M_n \in \mathbb{Z}\}$, which pair $\{m_1, M_2\}$ or $\{m_2, M_1\}$ will have the smallest and largest product, WITHOUT actually comparing the products, using only integer arithmetic?

Given that I want to determine:

$$ m_1 M_2 \lt m_2 M_1$$

using integer arithmetic, with integer results, I get:

$$ \Big\lceil {m_1 \over M_1} \Big\rceil \le \Big\lceil {m_2 \over M_2 } \Big\rceil$$

based on the results that ${-3 \over 2} = -1$

How do I use integer $\bmod$, in conjunction to the integer division, to determine which product will be bigger?

Please be gentle, I'm a programmer, not a math major. :)

Adrian
  • 191
  • This near duplicate of http://math.stackexchange.com/questions/1806546/how-to-determine-which-pair-will-have-the-smallest-and-largest-product-without-a gives the impression that you have an actual problem you want to solve, but instead of asking about it, you're going to ask seven similar variants, hoping someone will guess what you really want. What is the actual problem you are trying to solve? (Also, again, having handled the three cases $m_1=0$, $m_2=0$, and $m_1 = m_2 = 0$ with an if-else ladder, everything might as well be positive.) – Eric Towers May 31 '16 at 06:45
  • @EricTowers I'm trying to detect an overflow before it happens. The only piece of the puzzle I'm missing is this situation that I'm posing in this question. Actual Q would be I have 2 values $x$ and $y$ who's possible values are $x_{min} \le x \le x_{max}$ and $y_{min} \le y \le y_{max}$. What are the possible resulting min and max values? – Adrian May 31 '16 at 06:52
  • See http://stackoverflow.com/questions/199333/how-to-detect-integer-overflow-in-c-c for an overview, and http://www.informit.com/articles/article.aspx?p=1959565&seqNum=13 for excruciating detail on how to solve the problem you actually want to solve. – Eric Towers May 31 '16 at 06:55
  • @EricTowers, thanks. I'll see if it has what I'm looking for. – Adrian May 31 '16 at 07:18

0 Answers0