- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - fesetenv() function
The C fenv library fesetenv() function state the floating-point environment that contain the rounding or control mode. It is useful in many scenarios where we need to change the value of floating-point.
Syntax
Following is the C library syntax of the fesetenv() function.
fesetenv(const fenv_t *envp);
Parameters
This function accepts only a single parameter −
- fenv_t: It takes a pointer to an fenv_t object that contains the state to be restored.
Return Value
This function returns an integer value, which is −
zero, if the program works.
non-zero, if environment cannot be set.
Example 1
Following is the C library function to see the demonstration of fesetenv() function.
#include <stdio.h>
#include <fenv.h>
int main() {
fenv_t env;
fegetenv(&env);
// Perform some floating-point operations here
fesetenv(&env);
// Restore the saved environment
printf("Environment restored.\n");
return 0;
}
Output
The above code produces the following result −
Environment restored.
Example 2
Below the program illustrates the default behavior of floating-point environment using FE_DFL_ENV.
#include <stdio.h>
#include <fenv.h>
int main() {
// Set default environment, clearing all exceptions
fesetenv(FE_DFL_ENV);
printf("Default environment set, all exceptions cleared.\n");
return 0;
}
Output
On execution of above code, we get the following result −
Default environment set, all exceptions cleared.
c_library_fenv_h.htm
Advertisements