C Standard Library

C <fenv.h> - FE_DFL_ENV



The FE_DFL_ENV macro expands to a pointer to fenv_t which points to a full copy of the default floating-point environment. It can be used to select the default environment for fesetenv and feupdateenv functions.

Definition in the <fenv.h> header file is:

#define FE_DFL_ENV  /* implementation defined */ 

Example:

The example below shows the usage of FE_DFL_ENV macro.

#include <stdio.h>
#include <fenv.h>

#pragma STDC FENV_ACCESS ON

void Show_Environment() {
  if(fetestexcept(FE_DIVBYZERO)) 
    printf("Exceptions raised: FE_DIVBYZERO \n");
  if(fetestexcept(FE_INEXACT))   
    printf("Exceptions raised: FE_INEXACT \n");
  if(fetestexcept(FE_INVALID))   
    printf("Exceptions raised: FE_INVALID \n");
  if(fetestexcept(FE_OVERFLOW))  
    printf("Exceptions raised: FE_OVERFLOW \n");
  if(fetestexcept(FE_UNDERFLOW)) 
    printf("Exceptions raised: FE_UNDERFLOW \n");

  printf("Current rounding method: ");
  switch(fegetround()) {
    case FE_DOWNWARD: 
      printf("DOWNWARD"); break;
    case FE_TONEAREST:   
      printf("TO-NEAREST"); break;
    case FE_TOWARDZERO:   
      printf("TOWARD-ZERO"); break;
    case FE_UPWARD:  
      printf("UPWARD"); break;
    default:
      printf("unknown");
  }
  printf("\n");
}

int main (){
  printf("On startup: \n");
  Show_Environment();

  //raising FE_INVALID and FE_INEXACT exceptions
  feraiseexcept(FE_INVALID | FE_INEXACT);
  //changing to upward rounding direction mode
  fesetround(FE_UPWARD);

  printf("\nBefore restoration:\n");
  Show_Environment();

  //resetting to default environment
  fesetenv(FE_DFL_ENV);

  printf("\nAfter reset to default:\n");
  Show_Environment();

  return 0;
}

The output of the above code will be:

On startup: 
Current rounding method: TO-NEAREST

Before restoration:
Exceptions raised: FE_INEXACT 
Exceptions raised: FE_INVALID 
Current rounding method: UPWARD

After reset to default:
Current rounding method: TO-NEAREST

❮ C <fenv.h> Library