Did I find a bug?

I was trying to work my way around the maximum size of an array (2147483647) when I came across this anomaly :

void setup() {
  long i = 999_999_967L;
  println(int(i));
}

results in : 1000000000
The value of the long is incorrectly converted without throwing an error.

It turns out that this starts happening at 16777217.
Is this a bug or just a restriction that is not documented.
Cheers,
Adriaan.

2 Likes

Hi

1 Like

From the referents page:
int() : Converts any value of a primitive data type (boolean , byte , char , color , float , int , or long ) or String to its integer representation.

This does work but for a long this stops at 16777217.

At a a different place it says :
you’ll usually have to convert to a int using the (int) syntax.

This works for all values.
Thanks for your help.
Cheers,
Adriaan.

2 Likes