C语言 浮点异常(核心转储)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17299894/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 06:48:04  来源:igfitidea点击:

Floating point exception (core dumped)

cexceptionfloating-pointcoredumpfloating-point-exceptions

提问by

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.

在这种情况下,Complex 是我定义的类型定义。

typedef struct {
    int real, imag;
} Complex;

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

这是 main 中调用此函数的部分。

  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.

我之前调用了一些其他函数,这些函数将值放入 fft_input 和 ifft_bpsk_output,它们都是具有 64 个元素的复杂数组。

采纳答案by Salgar

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

您可能正在除以零或其他一些无意义的数字。你确定realand imagforIFFTOutput[i]不是零吗?也许就在之前打印出来?

回答by Qutus

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

我认为这可能是除以 0 的问题,请检查您的价值。

回答by Vipin Chaudhary

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 :)

我也遇到了同样的问题。这是由于使用的值大于您的数据类型可以处理的值。使用大小为 10^7 的数组,而您将其定义为 int A[10^7] 这将被转储,因为 int 数组无法处理这么大的大小..所以您必须使用适当的数据类型..谢谢:)