signal() with SIGFPE Requires Floating-Point Support

Last reviewed: July 17, 1997
Article ID: Q72726
5.10 6.00 6.00a 6.00ax 7.00 | 5.10 6.00 6.00a | 1.00 1.50 1.51 1.52
MS-DOS                      | OS/2            | WINDOWS
kbprg

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft C for MS-DOS, versions 5.0, 5.1, 6.0, 6.0a, and 6.0ax
        - Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft C/C++ for MS-DOS, version 7.0
        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, and 1.52
    

SUMMARY

The signal() function may be used to trap floating-point errors that would normally be fatal for an application. To trap these exceptions, the floating-point library must be linked in and become a part of the .EXE. One way that this can be done is by defining a double and initializing it to "0.0f" in your code.

If floating-point support has not been linked in for some reason and you try to set up a signal handler for SIGFPE (floating-point error), signal() will return SIG_ERR.

MORE INFORMATION

The types of floating-point exceptions that you can trap with the signal() function include the following:

  1. FPE_INVALID: Invalid number. This exception covers all
                            cases not covered by other exceptions [inputs
                            that are not a number (NaN), infinite,
                            out-of-range, or in an unsupported format].
    
    

  2. FPE_DENORMAL: Denormal number used. A denormal is defined as
                            a number that has a biased exponent of zero.
                            By providing a significand with leading zeros,
                            the range of possible negative exponents can
                            be extended by the number of bits in the
                            significand. Each leading zero is a bit of
                            lost accuracy, so the extended exponent range
                            is obtained by reducing significance.
    
    

  3. FPE_ZERODIVIDE: Divide by zero, or an answer where the
                            exponent has an infinite magnitude.
    
    

  4. FPE_OVERFLOW: Overflow. The magnitude of the result, while
                            finite, is too large to be represented in the
                            format requested.
    
    

  5. FPE_UNDERFLOW: Underflow. Just the opposite. The magnitude of
                            the result is too small to be represented in
                            the format requested. A denormal may be
                            generated at a loss of precision.
    
    

  6. FPE_INEXACT: Inexact result (precision exception). Usually
                            masked and ignored. Generated when the result
                            is not exact.
    
    

  7. FPE_UNEMULATED: Function not emulated in library.

  8. FPE_SQRTNEG: Negative square root. Generated when the
                            sqrt() or sqrtl() function returns a negative
                            number.
    
    

  9. FPE_STACKOVERFLOW: Floating-point stack overflow.

  10. FPE_STACKUNDERFLOW: Floating-point stack underflow.

  11. FPE_EXPLICITGEN: Explicit call. This exception is generated
                            when the raise() function is used to generate
                            a floating-point exception.
    
    
The following sample code attempts to set up a signal handler for SIGFPE without indicating that the floating-point code should be linked in, resulting in the return of SIG_ERR to signal(). Removing the comment corrects the problem.

Sample Code

/* Compile options used:
*/

#include <stdio.h>
#include <signal.h>
#include <float.h>
#include <math.h>

void func1(int, int);

void main(void)
{
//   double d = 0.0f;                    // Uncomment for workaround
   if(signal(SIGFPE, func1)==SIG_ERR)
      printf("signal Failed\n");
}

void func1(int i, int j)
{ }


Additional reference words: kbinf 6.00 6.00a 6.00ax 5.00 5.10 7.00 1.00
1.50
KBCategory: kbprg
KBSubcategory: CRTIss
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.