title: Mathematically Find Max Value without Conditional Comparison
body: <p>----------Updated ------------</p>
  
  <p>codymanix and moonshadow have been a big help thus far. I was able to solve my problem using the equations and instead of using right shift I divided by 29. Because with 32bits signed 2^31 = overflows to 29. Which works!</p>
  
  <p>Prototype in PHP</p>
  
  <pre><code>$r = $x - (($x - $y) &amp; (($x - $y) / (29)));
  </code></pre>
  
  <p>Actual code for LEADS (you can only do one math function PER LINE!!! AHHHH!!!)</p>
  
  <pre><code>DERIVDE1 = IMAGE1 - IMAGE2;
  DERIVED2 = DERIVED1 / 29;
  DERIVED3 = DERIVED1 AND DERIVED2;
  MAX = IMAGE1 - DERIVED3;
  </code></pre>
  
  <p>----------Original Question-----------<br>
  I don't think this is quite possible with my application's limitations but I figured it's worth a shot to ask.</p>
  
  <p>I'll try to make this simple. I need to find the max values between two numbers without being able to use a IF or any conditional statement. </p>
  
  <p>In order to find the the MAX values I can only perform the following functions</p>
  
  <pre><code>Divide, Multiply, Subtract, Add, NOT, AND ,OR
  </code></pre>
  
  <p>Let's say I have two numbers </p>
  
  <pre><code>A = 60;
  B = 50;
  </code></pre>
  
  <p>Now if A is always greater than B it would be simple to find the max value</p>
  
  <pre><code>MAX = (A - B) + B;
  ex. 
  10 = (60 - 50)
  10 + 50 = 60 = MAX
  </code></pre>
  
  <p>Problem is A is not always greater than B. I cannot perform ABS, MAX, MIN or conditional checks with the scripting applicaiton I am using. </p>
  
  <p>Is there any way possible using the limited operation above to find a value VERY close to the max?</p>