I’m compiling my code via the following command:
icc -ltbb test.cxx -o test
Then when I run the program:
time ./mp6 100 > output.modified
Floating exception
4.871u 0.405s 0:05.28 99.8% 0+0k 0+0io 0pf+0w
I get a “Floating exception”. This following is code in C++ that I had before the exception and after:
// before
if (j < E[i]) {
temp += foo(0, trr[i], ex[i+j*N]);
}
// after
temp += (j < E[i])*foo(0, trr[i], ex[i+j*N]);
This is boolean algebra… so (j < E[i]) is either going to be a 0 or a 1 so the multiplication would result either in 0 or the foo() result. I don’t see why this would cause a floating exception.
This is what foo() does:
int foo(int s, int t, int e) {
switch(s % 4) {
case 0:
return abs(t - e)/e;
case 1:
return (t == e) ? 0 : 1;
case 2:
return (t < e) ? 5 : (t - e)/t;
case 3:
return abs(t - e)/t;
}
return 0;
}
foo() isn’t a function I wrote so I’m not too sure as to what it does… but I don’t think the problem is with the function foo(). Is there something about boolean algebra that I don’t understand or something that works differently in C++ than I know of? Any ideas why this causes an exception?
Thanks,
Hristo
You are almost certainly dividing by zero in
foo.A simple program of
also prints
on my system.
So, you should check whether
eis 0 whens % 4is zero, or whethertis 0 whens % 4is 2 or 3. Then return whatever value makes sense for your situation instead of trying to divide by zero.@hristo: C++ will still evaluate the right-hand-side of a multiplication even if the left-hand-side is zero. It doesn’t matter that the result should be zero; it matters that
foowas called and evaluated and caused an error.Sample source:
Output: