小编smw*_*dia的帖子

如何用C双重表示无穷大?

我从计算机系统:程序员的观点中了解到,IEEE标准要求使用以下64位二进制格式表示双精度浮点数:

  • s:1位用于标志
  • exp:指数为11位
  • 压裂:分数为52位

+无穷大表示为具有以下模式的特殊值:

  • s = 0
  • 所有exp位都是1
  • 所有分数位均为0

我认为double的完整64位应按以下顺序排列:

(一个或多个)(EXP)(FRAC)

所以我编写以下C代码来验证它:

//Check the infinity
double x1 = (double)0x7ff0000000000000;  // This should be the +infinity
double x2 = (double)0x7ff0000000000001; //  Note the extra ending 1, x2 should be NaN
printf("\nx1 = %f, x2 = %f sizeof(double) = %d", x1,x2, sizeof(x2));
if (x1 == x2)
    printf("\nx1 == x2");
else
    printf("\nx1 != x2");
Run Code Online (Sandbox Code Playgroud)

但结果是:

x1 = 9218868437227405300.000000, x2 = 9218868437227405300.000000 sizeof(double) = 8
x1 == x2
Run Code Online (Sandbox Code Playgroud)

为什么数字是有效数字而不是无穷大错误?

为什么x1 == …

c floating-point

13
推荐指数
4
解决办法
4675
查看次数

如何使用 Eclipse + CDT + MinGW 更改优化级别?

我正在用 Eclipse + CDT + MinGW 编写一些 C 代码。

编译输出总是显示:

Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o Math.o "..\\Math.c" 
Run Code Online (Sandbox Code Playgroud)

如何更改命令行参数,例如 -O0、-Wall?

(我是 Eclipse IDE 的新手。)

c eclipse gcc eclipse-cdt

5
推荐指数
1
解决办法
6965
查看次数

标签 统计

c ×2

eclipse ×1

eclipse-cdt ×1

floating-point ×1

gcc ×1