Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is feupdateenv in C ?

Sheza Naveed

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The feupdateenv() function saves the floating point exceptions that have been raised currently. Next, it reestablishes the floating-point environment from the object that is being pointed by envp. Lastly, the function raises the floating point exception that were raised in the beginning. The following headers need to be included to make the function work:

#include <fenv.h>
#include <float.h>

Prototype

The function prototype is as follows:

int feupdateenv( const fenv_t* envp );

Parameters

The function takes the following parameter:

envp - pointer to the fenv_t object.

Return value

Figure 1: Return values in case of success and failure

Example

The following code shows different exceptions raised through this function:

#include <stdio.h>
#include <float.h>
#include <fenv.h>
#pragma STDC FENV_ACCESS ON
void show_fe_excepts(void)
{
printf("exceptions raised: ");
if(fetestexcept(FE_DIVBYZERO)) printf(" FE_DIVBYZERO");
if(fetestexcept(FE_INVALID)) printf(" FE_INVALID");
if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
printf("\n");
}
double func (double x)
{
fenv_t curr_excts;
feholdexcept(&curr_excts); // Save and clear current f-p environment.
// Raise inexact exceptions.
printf("In func(): x = %f\n", x = x/0);
show_fe_excepts();
feclearexcept(FE_DIVBYZERO); // clear exception
feupdateenv(&curr_excts); // calling the function
return x;
}
int main(void)
{
show_fe_excepts();
printf("func(DBL_MAX) = %f\n", func(DBL_MAX));
show_fe_excepts();
return 0;
}

RELATED TAGS

c

CONTRIBUTOR

Sheza Naveed
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring