函数定义在math.h
'''
inline long __cdecl lrintf (float x)
{
long retval;
__asm fld x
__asm fistp retval
return retval;
}
'''
测试程序:
'''
#include
#include
#include
using namespace std;
int main(int argc, char * const argv[])
{
float a[5] = {-1.8,-1.2,-0.5,0,0.8};
int b[5] = { 0 };
int c[5] = { 0 };
int d[5] = { 0 };
cout << "a[i] " << "a[i]取整 " << "a[i]-0.5取整 " << "a[i]+0.5取整" << endl;
for (int i = 0;i<5;i++)
{
a[i] = i;
b[i] = lrintf(a[i]);
c[i] = lrintf(a[i] - 0.5);
d[i] = lrintf(a[i] + 0.5);
//cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << " " << endl;
printf("%f\t%d\t%d\t%d\n", a[i], b[i], c[i], d[i]);
}
}
'''