# Maths adding problem

**URL:** <https://forum.arduino.cc/t/maths-adding-problem/935366>\
**Category:** Programming\
**Created:** [December 13, 2021, 11:06am UTC](https://forum.arduino.cc/t/maths-adding-problem/935366 "2021-12-13T11:06:11Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [December 13, 2021, 11:45am UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/21 "2021-12-13T11:45:34Z")

</div>

No need to test on the nano, just making sure you were using an 8-bit processor. There are some 32-bit boards that might default to larger integers for their math.

---

<div class="post-metadata">

**Author:** ![Uknod](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@Uknod](https://forum.arduino.cc/u/Uknod)\
**Post date:** [December 13, 2021, 11:47am UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/22 "2021-12-13T11:47:47Z")

</div>

ok, but it still doesn't explain why mine didn;t need the L after the numbers. Odd.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [December 13, 2021, 11:49am UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/23 "2021-12-13T11:49:05Z")

</div>

Hi,

> [@david\_2018](#):
>
> There are some 32-bit boards that might default to larger integers for their math.

> On the Arduino Due and SAMD based boards (like MKR1000 and Zero), an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) - 1).

Tom... 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [December 13, 2021, 12:11pm UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/24 "2021-12-13T12:11:48Z")

</div>

> [@Uknod](#):
>
> Change it to what, it seems pretty well named to me, arduino can't add up.

\* != +

(Why did it take until reply #19 to find out the board being used?)

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [December 13, 2021, 12:13pm UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/25 "2021-12-13T12:13:46Z")

</div>

> [@Uknod](#):
>
> ok, but it still doesn't explain why mine didn;t need the L after the numbers. Odd.

Post the exact code you are testing with.

---

<div class="post-metadata">

**Author:** ![Uknod](https://avatars.discourse-cdn.com/v4/letter/u/f17d59/32.png) [@Uknod](https://forum.arduino.cc/u/Uknod)\
**Post date:** [December 13, 2021, 12:25pm UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/26 "2021-12-13T12:25:03Z")

</div>

cant realy, its too big. And lot of stuff that is irrelevant, like wifi, card readers etc.  
I think it down to this equation that works:

```cpp
in1=(a0 * 4620)/(1032 - a0);

```

in1 and a0 are both unsigned long

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [December 13, 2021, 4:13pm UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/27 "2021-12-13T16:13:08Z")

</div>

> [@Uknod](#):
>
> `in1=(a0 * 4620)/(1032 - a0);`  
> in1 and a0 are both unsigned long

That explains why it worked for you. Your 4620 and 1032 are both being promoted to unsigned long because math is done on them with an unsigned long value.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 11, 2022, 4:13pm UTC](https://forum.arduino.cc/t/maths-adding-problem/935366/28 "2022-06-11T16:13:47Z")

</div>

Closed on June 11, 2022, 4:13pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/maths-adding-problem/935366.md?page=1)
