Facebook Page Twitter Page LinkedIn Page
× C++ Standard Library C++ STL Library


The FE_DIVBYZERO macro expands to a value of type integer constant expression that is distinct powers of 2, which uniquely identifies the floating-point exception raised on pole errors.

Pole errors occur when an operation has a result that is asymptotically infinite, such as divisions by zero, or log(0.0).

Definition in the <cfenv> header file is:

#define FE_DIVBYZERO  /*implementation defined power of 2*/                

MacrosDescription
FE_DIVBYZERO Pole error exception occurred in an earlier floating-point operation.
FE_INEXACT Inexact result exception occurred in an earlier floating-point operation (rounding was necessary to store the result).
FE_INVALID Invalid argument exception occurred (domain error occurred) in an earlier floating-point operation.
FE_OVERFLOW Overflow range error exception occurred in an earlier floating-point operation (result was too large to be representable).
FE_UNDERFLOW Underflow range error exception occurred in an earlier floating-point operation (result was subnormal with a loss of precision).
FE_ALL_EXCEPT Bitwise OR of all supported floating-point exceptions.

Certain library implementations may define additional macro constants in <cfenv> to identify additional floating-point exceptions (with their corresponding macros also beginning with FE_).

See math_errhandling for more details.

Example:

The below example shows the usage of FE_DIVBYZERO macro.

#include <iostream>
#include <cfenv>

#pragma STDC FENV_ACCESS ON

//volatile not needed if FENV_ACCESS is supported
volatile double zero = 0.0; 

using namespace std;
 
int main (){
  cout<<"1/0.0 = "<<(1/zero)<<"\n";
  if(fetestexcept(FE_DIVBYZERO))
    cout<<"Division by zero is reported.\n";
  else
    cout<<"Division by zero is not reported.\n";

  return 0;
}

The output of the above code will be:

1/0.0 = inf
Division by zero is reported.

❮ C++ <cfenv> Library