|
Author |
Topic: Variable inequality -or- Order of operations prob (Read 313 times) |
|
flight404
|
Variable inequality -or- Order of operations prob
« on: Jun 21st, 2003, 10:39pm » |
|
I am running on low sleep, but I came across this. Is it a bug? float timer = (100 - 50); timer /= 100; float brokenTimer = (100 - 50)/100; timer ends up as 0.5 which it should, but brokenTimer ends up as 0.0. Am I missing something, obvious perhaps?
|
|
|
|
skloopy
|
Re: Variable inequality -or- Order of operations p
« Reply #1 on: Jun 21st, 2003, 11:02pm » |
|
I think it's cause when you say "(100 - 50)/100;" you're using all integers so the variable gets rounded to 0 and then converted to a float. (100 - 50) / 100f; That should work. The "f" makes the 100 a float.
|
|
|
|
flight404
|
Re: Variable inequality -or- Order of operations p
« Reply #2 on: Jun 21st, 2003, 11:21pm » |
|
Ahhh. Just can't get used to the float/int/double discrepancies. 100 != 100.0 Who woulda thunk.
|
|
|
|
arielm
|
Re: Variable inequality -or- Order of operations p
« Reply #3 on: Jun 22nd, 2003, 2:23am » |
|
and in the same movie: inside the processing editor, 100.0 is considered as a float but with a standard java compiler, 100.0 would mean double! i guess the goal was to have a kind of safeguard against "f" forgetting, which is a very common problem...
|
Ariel Malka | www.chronotext.org
|
|
|
fry
|
Re: Variable inequality -or- Order of operations p
« Reply #4 on: Jun 22nd, 2003, 10:12pm » |
|
on Jun 22nd, 2003, 2:23am, arielm wrote:and in the same movie: inside the processing editor, 100.0 is considered as a float but with a standard java compiler, 100.0 would mean double! i guess the goal was to have a kind of safeguard against "f" forgetting, which is a very common problem... |
| yup, we did this for the beginners in the audience (it confuses the hell outta people). and for everyone else too, since in general, it's exceptionally rare that you'll need java's 64-bit doubles for this sort of graphics programming. also note that 100.0 does in fact equal 100, so if you compare: float a = 100.0; int b = 100; if (a == b) { // you'll see this message println("who'd have thought"); } because the 'b' will be upgraded to a float for the comparison, making it "if (100.0f == 100.0f)" internally. (this last bit is a java-ism, not p5) yeehaa.
|
|
|
|
|