You are not logged in.

#1 2010-04-06 17:15:05

mamacken
Member
From: Waterloo, Ontario, Canada
Registered: 2009-12-03
Posts: 9

[SOLVED] Confusing floating point exception

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

#2 2010-04-06 17:31:12

Cerebral
Forum Fellow
From: Waterloo, ON, CA
Registered: 2005-04-08
Posts: 3,108
Website

Re: [SOLVED] Confusing floating point exception

Hm - maybe divide-by-zero?  Make sure pixels[i] is never 0.

Offline

#3 2010-04-06 17:35:50

tch
Member
From: Slovakia
Registered: 2007-10-07
Posts: 31

Re: [SOLVED] Confusing floating point exception

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

#4 2010-04-06 17:36:36

mamacken
Member
From: Waterloo, Ontario, Canada
Registered: 2009-12-03
Posts: 9

Re: [SOLVED] Confusing floating point exception

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

Board footer

Powered by FluxBB