Previous Page
Next Page

feraiseexcept

Raises floating-point exceptions

#include <fenv.h>
int feraiseexcept ( int excepts  );

The feraiseexcept( ) function raises the floating-point exceptions represented by its argument. Unlike the fesetexceptflag( ) function, feraiseexcept( ) invokes any traps that have been enabled for the given exceptions.

The argument is a bitwise OR of the values of the following macros, defined in fenv.h to represent the floating-point exception flags:


FE_DIVBYZERO

This exception occurs when a nonzero, noninfinite number is divided by zero.


FE_INEXACT

This exception indicates that true result of an operation cannot be represented with the available precision, and has been rounded in the current rounding direction.


FE_INVALID

This exception flag is set when the program attempts an operation which has no defined result, such as dividing zero by zero or subtracting infinity from infinity. Some systems may also set FE_INVALID whenever an overflow or underflow exception is raised.


FE_OVERFLOW

The result of an operation exceeds the range of representable values.


FE_UNDERFLOW

The result of an operation is nonzero, but too small in magnitude to be represented.

Each of these macros is defined if and only if the system supports the corresponding floating-point exception. Furthermore, the macro FE_ALL_EXCEPT is the bitwise OR of all of the macros that are supported.

If feraiseexcept( ) raises the FE_INEXACT exception in conjunction with FE_UNDERFLOW or FE_OVERFLOW, then the underflow or overflow exception is raised first. Otherwise, multiple exceptions are raised in an unspecified order.

The function returns 0 if successful; a nonzero return value indicates that an error occurred.

Example

Although user programs rarely need to raise a floating-point exception by artificial means, the following example illustrates how to do so:

int result, except_set, except_test;

#pragma STDC FENV_ACCESS ON
feclearexcept (FE_ALL_EXCEPT);
except_set = FE_OVERFLOW;
result = feraiseexcept( except_set );
if ( result != 0 )
{
  printf( "feraisexcept( ) failed (%d)\n", result );
  exit( result );
}
except_test = fetestexcept( except_set );
if ( except_test != except_set )
  printf( "Tried to raise flags %X, but only raised %flags X.\n",
          except_set, except_test );

See Also

feclearexcept( ), feholdexcept( ), fetestexcept( ), fegetexceptflag( ), fesetexceptflag( )


Previous Page
Next Page