Format
#include <float.h> void _fpreset(void);
Language Level: Extension
_fpreset resets the floating-point unit to the default state that
the math library requires to function correctly. The value of
this default state may change between releases of this product.
You can determine the default state by calling _fpreset and then
calling _control87 with 0 as the parameter.
This function is often used within signal handlers. If a program traps floating-point error signals (SIGFPE) with signal, the program can safely recover from floating-point errors by calling longjmp.
_fpreset resets the floating-point unit of the current thread only. It does not affect any other threads that may be processing.
Return Value
There is no return value.
Example
This example establishes the function fphandler as a
floating-point error handler. The main program produces a
floating-point error, which causes control to be passed to
fphandler. The fphandler function calls _fpreset to reset the
floating-point unit, and then returns to main.
#include <stdio.h> #include <stdlib.h> #include <signal.h> #include <setjmp.h> #include <float.h>
jmp_buf mark;
void fphandler(int sig)
{
printf("Floating point signal = %d\n", sig);
_fpreset(); /* Reinitialize floating-point package */
longjmp(mark, -1);
}
int main(void)
{
double a = 1.0,b = 0.0,c;
if (SIG_ERR == signal(SIGFPE, (_SigFunc)fphandler))
return EXIT_FAILURE;
if (0 == setjmp(mark)) {
c = a/b; /* generate floating-point error */
printf("Should never get here\n");
}
printf("Recovered from floating-point error\n");
return 0;
/*******************************************************************
The output should be:
Floating point signal = 3
Recovered from floating-point error
*******************************************************************/
}
![]()
_clear87 -- Clear Floating-Point
Status Word
_control87 -- Set
Floating-Point Control Word
longjump -- Restore Stack
Environment
signal -- Handle Interrupt
Signals
_status87 -- Get Floating-Point
Status Word
<float.h>
Exception Handling for
Floating-Point Exceptions