I tried to slightly modify the example from the article:
#include <iostream>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
std::feclearexcept(FE_ALL_EXCEPT);
//int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO);
double x = 1.0;
double y = 0.0;
double result{};
asm volatile ("fldl %1\n"
"fdivl %2\n" : "=%t"(result) : "m"(x), "m"(y) : "memory");
std::cout << result << std::endl;
int e = std::fetestexcept(FE_ALL_EXCEPT);
if (e & FE_DIVBYZERO) {
std::cout << "division by zero\n";
}
if (e & FE_INEXACT) {
std::cout << "inexact\n";
}
if (e & FE_INVALID) {
std::cout << "invalid\n";
}
if (e & FE_UNDERFLOW) {
std::cout << "underflow\n";
}
if (e & FE_OVERFLOW) {
std::cout << "overflow\n";
}
return EXIT_SUCCESS;
}
but I get a warning (for clang++, but the same for G++ too):
warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]
#pragma STDC FENV_ACCESS ON
^
1 warning generated.
Another article reported, that the pragma is to treat the class of so-called C standard pragmas, but the former mentioned article does containing the code, which uses the pragma.
Is it allowed to use the pragma in C++ code? There is <cfenv>
header in C++. It alludes to the fact that this Floating-point environment is avaliable to using in C++. But this article reports about implementation dependent nature of the Floating-point environment. Is this touches upon C++?
Aucun commentaire:
Enregistrer un commentaire