[LCP]Problem with SIGFPE

Aaron Walker ka0ttic at cfl.rr.com
Fri Feb 28 18:31:02 UTC 2003


On Thu, 2003-02-27 at 08:58, Jesús Peco wrote:
> I would be very pleased if you could help tell
> me what's wrong with the code below. I'm trying
> to catch SIGFPE but without results.
> 
> I have a debian woody 3.0 on a PC
> with libc6 2.2.5-11.2
> and g++ 3.0.4
> 
> Thank you very much.
> 
> #include <iostream>
> #include <csignal>
> 
> void catchFPE(int) {
>   std::signal(SIGFPE, catchFPE);
>   std::cerr << "Float Point Exception. Exit..." << std::endl;
>   std::exit(1);
> }
> 
> int main()
> {
>  double a=20.0, b=3.0, c;
> 
>  std::signal(SIGFPE, catchFPE);
> 
>   while(b>-3.0) {
>     std::cout << a << "/" << b <<  "=" << a/b << std::endl;
>     b=b-1.0;
>     c=a/b;
>  }
>  return 0;
> }
> 
> I have also tried de "equivalent" in "C" with no results.
> 
> #include <stdio.h>
> #include <signal.h>
> 
> void handler(int sig);
> 
> int main()
> {
>  double i;
> 
>  signal(SIGFPE, handler);
> 
> ....
> }

According to my book Advanced Linux Programming, Appendix C (Table of
Signals) states:

SIGPFE: the process has executed an invalid floating-point math
instruction.  Depending on how the CPU is configured, and invalid
floating-point operation may return a special non-number value such as
inf (infinity) or NaN (not a number) instead of raising SIGPFE.

HTH,
Aaron

> _______________________________________________
> This is the Linux C Programming List
> :  http://lists.linux.org.au/listinfo/linuxcprogramming List






More information about the linuxCprogramming mailing list