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.
Page Index Toggle Pages: 1
1 / 2 = 0 ? (Read 629 times)
1 / 2 = 0 ?
Sep 1st, 2009, 9:26am
 
I'm working with v1.0.3:

float x = 1 / 2;
println(x);

outputs "0.0"

what the... wtf?

Am I missing something really stupid?

ps -- I noticed this when I discovered that

translate( ((1/2) * (scaleX)), 0);

produced a different result than

translate( ((.5) * (scaleX)), 0);

playing a bit more: x = 1, y = 2; println(x/y) is correct.
Re: 1 / 2 = 0 ?
Reply #1 - Sep 1st, 2009, 9:42am
 
this quesion pops up once in a while Smiley
http://processing.org/reference/troubleshooting/#integers

you can solve it by adding .0  like
float x = 1.0 / 2;
println(x);
Re: 1 / 2 = 0 ?
Reply #2 - Sep 1st, 2009, 9:50am
 
Huh.

What's *really* weird is that somehow I wrote graphics code that worked even though it seems my reasoning was completely off the mark.

Interesting.
Page Index Toggle Pages: 1