#include <math.h> #include <iostream> using namespace std; #define fn rint // https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html #define xstr(s) str(s) #define str(s) #s int main() { const char* name = xstr(fn); double a[] = { -0.6, -0.5, -0.4, 0.4, 0.5, 0.6 }; for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) { double x = a[i]; cout << name << '(' << x << ") = " << fn(x) << endl; } } #include <math.h> double nearbyint(double x); float nearbyintf(float x); long double nearbyintl(long double x); double rint(double x); float rintf(float x); long double rintl(long double x); double round(double x); float roundf(float x); long double roundl(long double x); double trunc(double x); float truncf(float x); long double truncl(long double x); long lrint(double x); long lrintf(float x); long lrintl(long double x); long long llrint(double x); long long llrintf(float x); long long llrintl(long double x); #include <fenv.h> int feclearexcept(int excepts); int fegetexceptflag(fexcept_t *flagp, int excepts); int feraiseexcept(int excepts); int fesetexceptflag(const fexcept_t *flagp, int excepts); int fetestexcept(int excepts); int fegetround(void); int fesetround(int rounding_mode); int fegetenv(fenv_t *envp); int feholdexcept(fenv_t *envp); int fesetenv(const fenv_t *envp); int feupdateenv(const fenv_t *envp);标签:envp,int,double,float,long,excepts,round From: https://www.cnblogs.com/funwithwords/p/17038687.html