淡泊明志 宁静致远
分类: C/C++
2006-12-05 12:51:15
【C语言库函数源代码】
【本程序在Dev C++ 4.9.9.2 下编译通过】
float my_fabs01 (float
fnumber)
{
float ret;
__asm__ (
"fabs\n\r"
:
"=t" (ret)
:
"0" (fnumber)
);
return ret;
}
//直接调用了奔腾系列CPU浮点指令系统中的求浮点数绝对值指令。
float my_fabs02(float fnumber)
{
*( (int *)
&fnumber) &=0x7FFFFFFF;
return
fnumber;
}
//取得浮点数的地址,然后把符号位置0。
double my_fabs03(double
dnumber)
{
*( ( (int *)
& dnumber) + 1) &=0x7FFFFFFF;
return
dnumber;
}
int main()
{
printf("%f\n",my_fabs01(0.000001));
printf("%f\n",my_fabs01(-0.000001));
printf("%f\n",my_fabs01(1.1234567));
printf("%f\n",my_fabs01(-1.1234567));
printf("****************************\n");
printf("%f\n",my_fabs02(0.000001));
printf("%f\n",my_fabs02(-0.000001));
printf("%f\n",my_fabs02(1.1234567));
printf("%f\n",my_fabs02(-1.1234567));
printf("****************************\n");
printf("%f\n",my_fabs03(111111111.0000019));
printf("%f\n",my_fabs03(-111111111.0000019));
printf("%f\n",my_fabs03(1234567.12345678));
printf("%f\n",my_fabs03(-1234567.12345678));
system("pause");
return 0;
}