1570af302Sopenharmony_ci#include <fenv.h> 2570af302Sopenharmony_ci#include <math.h> 3570af302Sopenharmony_ci 4570af302Sopenharmony_cifloat nearbyintf(float x) 5570af302Sopenharmony_ci{ 6570af302Sopenharmony_ci#ifdef FE_INEXACT 7570af302Sopenharmony_ci #pragma STDC FENV_ACCESS ON 8570af302Sopenharmony_ci int e; 9570af302Sopenharmony_ci 10570af302Sopenharmony_ci e = fetestexcept(FE_INEXACT); 11570af302Sopenharmony_ci#endif 12570af302Sopenharmony_ci x = rintf(x); 13570af302Sopenharmony_ci#ifdef FE_INEXACT 14570af302Sopenharmony_ci if (!e) 15570af302Sopenharmony_ci feclearexcept(FE_INEXACT); 16570af302Sopenharmony_ci#endif 17570af302Sopenharmony_ci return x; 18570af302Sopenharmony_ci} 19