﻿# V2634\. MISRA\. Features from <fenv\.h\> should not be used\.

This diagnostic rule is based on the [MISRA](https://www.misra.org.uk/) \(Motor Industry Software Reliability Association\) software development guidelines\.

This diagnostic rule is relevant only for C\. 

Avoid using functions or macros from the `<fenv.h>` header file\. In some cases, using the functionality of this file may result in unspecified or undefined behavior\.

Below are some potential issues that can arise when working with `<fenv.h>`\.

**Issue N1**\. The order in which floating\-point exception flags are set when calling [`feraiseexcept`](https://en.cppreference.com/w/c/numeric/fenv/feraiseexcept) is not specified\.

**Issue N2**\. Calling [`fesetenv`](https://en.cppreference.com/w/c/numeric/fenv/feenv) and/or [`feupdateenv`](https://en.cppreference.com/w/c/numeric/fenv/feupdateenv) with an argument that was not obtained via [`feholdexcept`](https://en.cppreference.com/w/c/numeric/fenv/feholdexcept) / [`fegetenv`](https://en.cppreference.com/w/c/numeric/fenv/feenv), or by expanding the [`FE_DFL_ENV`](https://en.cppreference.com/w/c/numeric/fenv/FE_DFL_ENV) macro leads to undefined behavior\.

**Issue N3**\. Some implementations of functions from the `<math.h>` header support rounding floating\-point numbers only to the nearest representable value \([`FE_TONEAREST`](https://en.cppreference.com/w/c/numeric/fenv/FE_round)\)\. If a different rounding mode is set, the result of calling such functions can be unpredictable\.

The examples where the analyzer issues warnings:

```cpp
void clear_overflow_status()
{
  feclearexcept(FE_OVERFLOW);
}

void change_rounding_direction()
{
  fesetround(FE_DOWNWARD);
}

double some_computation(void)
{
  int r = feraiseexcept(FE_OVERFLOW | FE_INEXACT);
  printf("feraiseexcept() %s\n", (r?"fails":"succeeds"));
  return 0.0;
}
```