// filename:c2011-7-6-4-4-ex.c // original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // C2011 7.6.4.4 The feupdateenv function // compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013 // compile errors and/or wornings: // (c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Target: x86_64-apple-darwin11.4.2 //Thread model: posix // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. #include // Example #include double f(double x) { #pragma STDC FENV_ACCESS ON double result; fenv_t save_env; if (feholdexcept(&save_env)) return /* indication of an environmental problem */x; result = x * x; // compute result if (/* test spurious underflow */1) // How can I test spurious underflow? if (feclearexcept(FE_UNDERFLOW)) return /* indication of an environmental problem */x; if (feupdateenv(&save_env)) return /* indication of an environmental problem */x; return result; } int main(void) { double d=3.5; return printf("7.6.4.4 The feupdateenv function %f \n",f(d)); } // output may be // 7.6.4.4 The feupdateenv function 12.250000