Floating point exception (core dumped)
Asked Answered
R

3

6

I have a long program, which consists of one header file, and two source files, in the first one I have written the implementations of the functions, and in the second one (which is my main), I call and execute them. Though, at one point I get an error message saying

Floating point exception (core dumped)

and the program stops.

As I said there are lots of lines of code, therefore, I'm not able to post my whole source code here, though I will post the most relevant parts, and where error occurs.

My error occurs when I try to call this function (below you can find its implementation):

void chest_first(Complex* FFTInput, Complex* IFFTOutput, Complex* HFirst)
{
    int i;

    for(i = 0; i < 64; i++)
    {
        HFirst[i].real = FFTInput[i].real / IFFTOutput[i].real;
        HFirst[i].imag = FFTInput[i].imag / IFFTOutput[i].imag;
    }

}

In this case Complex, is a type definition that I have defined.

typedef struct {
    int real, imag;
} Complex;

Here is the part from the main, where this function is called.

  Complex HFirst[64];

  if((strcmp(channel, "LS") == 0) || (strcmp(channel, "ls") == 0))
  {
      if(i == 1)
        chest_first(fft_input, ifft_bpsk_output, HFirst);
      .
      .
      .
  }

I have earlier called some other function, which put values to fft_input and ifft_bpsk_output, which are both Complex arrays with 64 elements.

Roid answered 25/6, 2013 at 14:22 Comment(2)
IFFTOutput[i].real (or .imag) is 0. (Or -1, and the dividend is INT_MIN is another possibility on some platforms.) Confusingly, an integer division by 0 gives rise to SIGFPE.Fleeting
@Daniel Fischer, your insightful comment about the quirks of integer division and causing SIGFPE deserves an answer posting.Jubbah
S
6

You're probably dividing by zero or some other nonsensical number. Are you sure real and imag for IFFTOutput[i] isn't zero? Print it out just before perhaps?

Sawyers answered 25/6, 2013 at 14:24 Comment(1)
Yes, that was the problem, I completely missed it. I was dividing with 0.Roid
J
4

I think it could be a problem of division by 0, check your value about that.

Joellyn answered 25/6, 2013 at 14:30 Comment(0)
G
-1

I was also having the same problem.It occurs due to using value greater than which your datatype can handle for ex. using an array of size 10^7 while you defined it as int A[10^7] this will dumped becouz an int array cannot handle this much size.. So you have to use appropriate datatypes.. thank you :)

Guardhouse answered 6/10, 2014 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.