user18958: I had a problem in a program where the result of product is not what it's supposed to be. For example: 775*775 gives 10801 instead of 6006025.
To try to isolate and resolve the problem, I made a simple sketch to test the result of different products. What I found is that if I do the same product in this way: 775/100.00*775/100.00 then multiply the result by 10000 I get the right value: 600625.00
The attached pictures illustrate what I said.
While I can use this solution in my initial program by I still want to do the multiplication directly as more operations means more time.
I would appreciate any help. Thank you. 


user4143: Integer overflow. You're multiplying an int by an int then assigning it to a long.  Instead if you multiply a long by a long, or an int by a long, or a long by an int, it should work.
unsigned long res = 775L * 775;

The L suffix tells the compiler to treat it as a long, not an int.

18958: <p>I had a problem in a program where the result of product is not what it's supposed to be. For example: 775*775 gives 10801 instead of 6006025.</p>

<p>To try to isolate and resolve the problem, I made a simple sketch to test the result of different products. What I found is that if I do the same product in this way: 775/100.00*775/100.00 then multiply the result by 10000 I get the right value: 600625.00</p>

<p>The attached pictures illustrate what I said.</p>

<p>While I can use this solution in my initial program by I still want to do the multiplication directly as more operations means more time.</p>

<p>I would appreciate any help. Thank you.<a href="https://i.stack.imgur.com/IJbFY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IJbFY.jpg" alt="enter image description here"></a> </p>

<p><a href="https://i.stack.imgur.com/I8zD8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I8zD8.jpg" alt="enter image description here"></a></p>
 4143: <p>Integer overflow. You're multiplying an <code>int</code> by an <code>int</code> then assigning it to a <code>long</code>.  Instead if you multiply a <code>long</code> by a <code>long</code>, or an <code>int</code> by a <code>long</code>, or a <code>long</code> by an <code>int</code>, it should work.</p>

<pre><code>unsigned long res = 775L * 775;
</code></pre>

<p>The <code>L</code> suffix tells the compiler to treat it as a long, not an int.</p>
