|
Author |
Topic: int float mismatch causes hang (Read 265 times) |
|
kevinP
|
int float mismatch causes hang
« on: May 8th, 2004, 1:54am » |
|
This seems to reliably (well twice) cause Processing (Alpha 0068, Linux) to hang: Code: for(int i = 0; i < width; i += 0.1) { point(x, x+1); } |
| Shouldn't it fail with some kind of error? Strangely (?), this doesn't hang: Code:
|
Kevin Pfeiffer
|
|
|
TomC
|
Re: int float mismatch causes hang
« Reply #1 on: May 8th, 2004, 2:11am » |
|
OK, it's not immediately obvious, but if you add a float to an int, it will only use the whole number part of the float. The whole number part of 0.1 is 0. (The whole number part of 0.9 is also 0). That means that your first code is actually an infinite loop, since i += 0.1 is equivalent to i += 0 when i is an int. The second snippet doesn't crash because it's perfectly OK to add 0.1 to an integer. But it won't change the value of i.
|
|
|
|
kevinP
|
Re: int float mismatch causes hang
« Reply #2 on: May 8th, 2004, 10:47am » |
|
Thanks Tom! (See what happens when I post a bug report: operator error).
|
Kevin Pfeiffer
|
|
|
|