Why does a%b produce SIGFPE when b is zero?

后端 未结 2 1182
温柔的废话
温柔的废话 2020-11-29 08:08

Today I was tracking down a floating point exception in some code I had just written. It took a little while to find because it was actually caused by taking an integer mod

相关标签:
2条回答
  • 2020-11-29 08:48

    Take a look at this page.

    Relevant part for your question:

    SIG is a common prefix for signal names; FPE is an acronym for floating-point exception. Although SIGFPE does not necessarily involve floating-point arithmetic, there is no way to change its name without breaking backward compatibility.

    0 讨论(0)
  • 2020-11-29 08:58

    The operation triggers SIGFPE:

    SIG is a common prefix for signal names; FPE is an acronym for floating-point exception. Although SIGFPE does not necessarily involve floating-point arithmetic, there is no way to change its name without breaking backward compatibility.

    GDB is a bit clearer about this and calls it "Arithmetic exception":

    (gdb) run
    Starting program: /home/emil/float
    
    Program received signal SIGFPE, Arithmetic exception.
    0x0804837d in main () at float.c:4
    4           int c=a%b;
    
    0 讨论(0)
提交回复
热议问题