我正在学习 float 的算术。我写了下面的代码。但不会发生浮点异常。我的环境是 Cent OS 6.4 (x86_64)。
请教我这个道理。
#include <stdio.h>
int
main(void)
{
double a,b,c;
unsigned short int fctr;
a=3.0;
b=0.0;
c=1.0;
asm volatile(
"fstcw %w0" // get FPU control word
:"=m"(fctr):);
printf("FPU control word= %X\n", fctr);
fctr = fctr ^ 0x4;
printf("FPU control word= %X\n", fctr);
asm volatile(
"fldcw %w0" // set operand to FPU control word
: :"m"(fctr));
asm volatile(
"fstcw %w0" // get FPU control word
:"=m"(fctr):);
printf("FPU control word= %X\n", fctr);
c = a/b;
return 0;
}
最佳答案
可能是因为默认情况下 x86_64 架构使用 SSE2 而不是 x87 进行浮点运算。 (statusword属于x87)
使用 -S 编译并检查生成的汇编器是否真的是 x87。
在 this 中搜索 MXCSR链接
关于linux - 为什么不出现浮点异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936237/