We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › variable longs not working
Page Index Toggle Pages: 1
variable longs not working (Read 274 times)
variable longs not working
Dec 12th, 2008, 9:12am
 
Hello all,

Perhaps someone can explain what I am missing. I wrote this code:

long test;
void setup()
{
 test = 2147483648;
}
void draw()
{
}

and when I try to run I get the following error:

"the literal 2147483648 of type int is out of range"

What is going on?

Nightwork
Re: variable longs not working
Reply #1 - Dec 12th, 2008, 11:04am
 
Long literal numbers must be written 2147483648L (or 2147483648l but I find it less readable, we can mix 1 and l without proper font).
It is the reverse for decimal numbers: 3.1415926 is a double, if you need a float, you must write 3.1415926F (or f).
Although it is a Java rule, I think Processing is doing some magic to do automatic casts.
float test = 3.1415; is illegal in Java but OK in Processing (thanks to pre-processing, I think).
Re: variable longs not working
Reply #2 - Dec 13th, 2008, 1:37am
 
Thank you very much. Is there a way for this information to get added to the page about long variable. Here is a link to the page I using to try to figure it out how to use longs.

http://www.processing.org/reference/long.html
Page Index Toggle Pages: 1