Hello everyone,

I came across math_errhandling in MATH_ERRNO, MATH_ERREXCEPT, math_errhandling - cppreference.com and I was trying to run the example code of standard library math functions mentioned in cppreference.com that uses the math error handling however I noticed that even if MATH_ERRNO is enabled in nvc++ it is not working properly.

Starting from the example presented in std::sqrt, std::sqrtf, std::sqrtl - cppreference.com I wrote the following code:

```
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cfenv>
#include <cstring>
#pragma STDC FENV_ACCESS ON
int main()
{
// normal use
std::cout << "sqrt(100) = " << std::sqrt(100) << '\n'
<< "sqrt(2) = " << std::sqrt(2) << '\n'
<< "golden ratio = " << (1+std::sqrt(5))/2 << '\n';
// special values
std::cout << "sqrt(-0) = " << std::sqrt(-0.0) << '\n';
// error handling
errno = 0;
const auto errno_enabled = math_errhandling & MATH_ERRNO;
const auto check_fe_except = math_errhandling & MATH_ERREXCEPT;
std::cout << "errno_enabled: " << errno_enabled << " check_fe_except: " << check_fe_except << std::endl;
std::feclearexcept(FE_ALL_EXCEPT);
double d = std::sqrt(-1);
std::cout << "sqrt(-1.0) = " << d << '\n';
std::cout << " errno = " << errno << " " << std::strerror(errno) << '\n';
if(errno == EDOM)
std::cout << " errno = EDOM " << std::strerror(errno) << '\n';
if(std::fetestexcept(FE_INVALID))
std::cout << " FE_INVALID raised\n";
}
```

Compiling the above code with nvc++ I get the following output:

```
$ nvc++ ../t_sqrt.cpp -o t_sqrt_nvc++
"../t_sqrt.cpp", line 7: warning: unrecognized STDC pragma
#pragma STDC FENV_ACCESS ON
^
$ ./t_sqrt_nvc++
sqrt(100) = 10
sqrt(2) = 1.41421
golden ratio = 1.61803
sqrt(-0) = 0
errno_enabled: 1 check_fe_except: 2
sqrt(-1.0) = -nan
errno = 0 Success
FE_INVALID raised
```

Iām using NVHPC 22.3 and Iām testing this on linux 20.04.

The above output suggests to me that while errno should be set to EDOM it is not set properly. Instead only the FE_INVALID is set.

Is there any way to enable the update of the errno variable in such cases or is there some other issue that this variable is not set to the ERRNO value?

Compiling the same code with `nvcc`

returns the expected output:

```
$ nvcc ../t_sqrt.cpp -o t_sqrt_nvcc
$ ./t_sqrt_nvcc
sqrt(100) = 10
sqrt(2) = 1.41421
golden ratio = 1.61803
sqrt(-0) = -0
errno_enabled: 1 check_fe_except: 2
sqrt(-1.0) = -nan
errno = 33 Numerical argument out of domain
errno = EDOM Numerical argument out of domain
FE_INVALID raised
```

Thank you very much in advance for your time.