# Issues with variables dimentions

**URL:** <https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922>\
**Category:** Programming\
**Created:** [March 10, 2024, 8:14pm UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922 "2024-03-10T20:14:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![martina0102](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@martina0102](https://forum.arduino.cc/u/martina0102)\
**Post date:** [March 10, 2024, 8:14pm UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/1 "2024-03-10T20:14:49Z")

</div>

Hello,  
I'm working on a robotic project and I'm trying to implement inverse kinematics.  
My issue is that, with an Arduino Uno R3, I can't seem to figure out how to work with big numbers.  
An example would be 2_147_299: the correct result is 87906 but the arduino displays 22370 as the result. This result is given when using a long variable, which should go as far as 2^35.  
I don't really know what the problem could be and I can't seem to find any solution online.  
If anyone has any idea why this is happening, it would help me a lot!  
Thanks  
P.S. I'll be inserting the basic code I estrapulated from the more complex code of my project in order to examine better the problem

```arduino
long a;

void setup() {
  Serial.begin(9600);
  a = 2*147*299;
  Serial.println(a);
}

void loop() {

}

```

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [March 10, 2024, 8:21pm UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/2 "2024-03-10T20:21:01Z")

</div>

> [@martina0102](#):
>
> This result is given when using a long variable, which should go as far as 2^35.

0 to **2^32** for unsigned long. -(2^31) to (2^31-1) for long.

```arduino
uint32_t a;

void setup() {
  Serial.begin(115200);
  a = 2*147*299UL;
  Serial.println(a);
}

void loop() {

}
```

---

<div class="post-metadata">

**Author:** ![martina0102](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@martina0102](https://forum.arduino.cc/u/martina0102)\
**Post date:** [March 10, 2024, 9:50pm UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/3 "2024-03-10T21:50:28Z")

</div>

That's great, thank you so much. The code works but I can't seem to make it work if I use variables instead of the three values inside the multiplication.  
Is this a syntax error?

```arduino
uint32_t a;
int b = 147;
int c = 299;
int d = 2;

void setup() {
  Serial.begin(9600);
  a = b*c*d UL;
  Serial.println(a);
}

void loop() {

}

```

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [March 10, 2024, 10:37pm UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/4 "2024-03-10T22:37:16Z")

</div>

> [@martina0102](#):
>
> Is this a syntax error?

What did the compiler say about it?

---

<div class="post-metadata">

**Author:** ![martina0102](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@martina0102](https://forum.arduino.cc/u/martina0102)\
**Post date:** [March 11, 2024, 6:08am UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/6 "2024-03-11T06:08:00Z")

</div>

The compiler doesn’t signal any error but still does the calculation wrong

---

<div class="post-metadata">

**Author:** ![martina0102](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@martina0102](https://forum.arduino.cc/u/martina0102)\
**Post date:** [March 11, 2024, 6:08am UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/7 "2024-03-11T06:08:43Z")

</div>

That’s perfect, It works perfectly now.  
Thank you to all of you!

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [March 11, 2024, 11:07am UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/8 "2024-03-11T11:07:13Z")

</div>

> [@martina0102](#):
>
> The compiler doesn’t signal any error but still does the calculation wrong

Are you sure? I get this because the UL is only for integer literal constants:

```arduino
sketch_mar11a:8:13: error: expected ';' before 'UL'
   a = b*c*d UL;
             ^~
exit status 1
expected ';' before 'UL'

```

Why not just use the an appropriate datatype to begin with?

```arduino
uint32_t a;
uint32_t b = 147;
uint32_t c = 299;
uint32_t d = 2;

void setup() {
  Serial.begin(115200);
  a = b*c*d;
  Serial.println(a);
}

void loop() {
}
```

---

<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:** [September 7, 2024, 11:07am UTC](https://forum.arduino.cc/t/issues-with-variables-dimentions/1233922/9 "2024-09-07T11:07:52Z")

</div>

Closed on September 7, 2024, 11:07am UTC

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