sigfpe

what does C/C++ handler SIGFPE?

对着背影说爱祢 提交于 2020-12-30 07:36:32
问题 well, I have searched the articles about SIGFPE ,then I wrote a few tests but it's behavoir is strange. Then I have to post it here to ask for help. Is the GCC/G++ or ISO C++ clearly defined what happens if divide by zero? 1) I searched the article : Division by zero does not throw SIGFPE it sames the output is inf 2) If I rewrite it as the following: void signal_handler (int signo) { if(signo == SIGFPE) { std::cout << "Caught FPE\n"; } } int main (void) { signal(SIGFPE,(*signal_handler));

Why was SIGFPE used for integer arithmetic exceptions?

倖福魔咒の 提交于 2020-02-21 10:57:45
问题 Why was SIGFPE used for integer arithmetic exceptions, such as division by zero, instead of creating a separate signal for integer arithmetic exceptions or naming the signal in the first place for arithmetic exceptions generally? 回答1: IEEE Std 1003.1 Standard defines SIGFPE as: Erroneous arithmetic operation. And doesn't really mention floating point operations. Reasoning behind this is not clearly stated, but here's my take on it. x86 FPU can operate on both integer and floating point data

Floating point exception when reading real values from an input file

六月ゝ 毕业季﹏ 提交于 2019-12-20 02:56:23
问题 I try to read a float value from an input file in Fortran . To do so I use this code : ... INTEGER :: nf REAL :: re OPEN(newunit=nf, file='toto.txt') READ(unit=nf, fmt=*) re ... with toto.txt a text file containing my real value : 10.1001 ! this value is supposed to be read by the Fortran program If I compile and execute like this, everything works well. But I get some trouble when I compile and execute with fpe option. I have a error at the readding line that looks like: Program received

Can I ignore a SIGFPE resulting from division by zero?

爱⌒轻易说出口 提交于 2019-12-10 16:17:13
问题 I have a program which deliberately performs a divide by zero (and stores the result in a volatile variable) in order to halt in certain circumstances. However, I'd like to be able to disable this halting, without changing the macro that performs the division by zero. Is there any way to ignore it? I've tried using #include <signal.h> ... int main(void) { signal(SIGFPE, SIG_IGN); ... } but it still dies with the message "Floating point exception (core dumped)". I don't actually use the value,

Stopping the debugger when a NaN floating point number is produced without a code change

杀马特。学长 韩版系。学妹 提交于 2019-12-08 19:37:48
问题 I read this and this. The quintessence is that one can throw a SIGFPE if a nan is produced by including fenv.h and enabling all floating point exceptions but FE_INEXACT by feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); Thus, the code changes form int main () { double dirty = 0.0; double nanvalue = 0.0/dirty; return 0; } to #include <fenv.h> int main () { feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); // Enable all floating point exceptions but FE_INEXACT double dirty = 0.0; double nanvalue = 0.0

Floating point exception when reading real values from an input file

ε祈祈猫儿з 提交于 2019-12-02 00:02:00
I try to read a float value from an input file in Fortran . To do so I use this code : ... INTEGER :: nf REAL :: re OPEN(newunit=nf, file='toto.txt') READ(unit=nf, fmt=*) re ... with toto.txt a text file containing my real value : 10.1001 ! this value is supposed to be read by the Fortran program If I compile and execute like this, everything works well. But I get some trouble when I compile and execute with fpe option. I have a error at the readding line that looks like: Program received signal SIGFPE: Floating-point exception - erroneous arithmetic operation Backtrace for this error #0

Floating Point Exception Core Dump

倖福魔咒の 提交于 2019-12-01 16:17:16
I am newbie on the Linux signals, please help. The following code get core dump when run in Linux 2.6 gcc. $ ./a.out Floating point exception (core dumped) The questions: 1. Since a process signal mask is installed, shouldn't the "SIGFPGE" generated by line 40 volatile int z = x/y; be blocked? 2. If it is not blocked, since a signal handler has been installed, shouldn't the "SIGFPE" be captured by the signal handler, instead of a core dump? 3. If I commented out line 40 volatile int z = x/y; , and use line 42 raise(SIGFPE); instead, then everything works as I expected. What is the difference

Floating Point Exception Core Dump

故事扮演 提交于 2019-12-01 14:35:46
问题 I am newbie on the Linux signals, please help. The following code get core dump when run in Linux 2.6 gcc. $ ./a.out Floating point exception (core dumped) The questions: 1. Since a process signal mask is installed, shouldn't the "SIGFPGE" generated by line 40 volatile int z = x/y; be blocked? 2. If it is not blocked, since a signal handler has been installed, shouldn't the "SIGFPE" be captured by the signal handler, instead of a core dump? 3. If I commented out line 40 volatile int z = x/y;