You are not logged in.
Howdy folks,
I've been writing up a C program to compute the center of mass of atmospheric bodies from radar images, and I am getting a bizarre error.
Here is the piece of code that is giving me a problem:
/* compute center of mass at each threshold */
for (i = 0; i < 3; i++) {
points[i].y = points[i].y / pixels[i];
points[i].x = points[i].x / pixels[i];
}
The data type for the array "pixels" is int, and the data type for "points" is point, defined as
typedef struct {
int x, y;
} point;
The error I am getting a runtime is as follows:
Floating point exception
I can post more details as needed to diagnose this problem (such as variable values at runtime etc.)
Thanks in advance!
Last edited by mamacken (2010-04-06 18:56:54)
"In questions of science the authority of a thousand is not worth the humble reasoning of a single individual."
- Galileo Galilei
Offline
Hm - maybe divide-by-zero? Make sure pixels[i] is never 0.
Offline
Looks like a division by zero, try like that:
for (i = 0; i < 3; i++) {
if (pixels[i]) {
points[i].y /= pixels[i];
points[i].x /= pixels[i];
}
}
Last edited by tch (2010-04-06 17:36:12)
Offline
Good lord thank you, that was the problem!. I can't believe I ignored such a blantant error in logic. It always helps to have a fresh pair of eyes when one has been focused so intensely on something.
"In questions of science the authority of a thousand is not worth the humble reasoning of a single individual."
- Galileo Galilei
Offline