平方根的3中,作爲估計由鎢阿爾法:爲什麼gdb將sqrt(3)評估爲0?
1.7320508075688772935274463415058723669428052538103806280558...
當我用C做sqrt(3)
,它的計算結果爲0。爲什麼呢?
EDIT4:以下介紹如何在GDB中重現此問題。創建test.c
如下:
#include <stdio.h>
#include <math.h>
int main()
{
printf("sqrt(3): %f\n", sqrt(3));
return 0;
}
編譯:
gcc -O0 -g -Wall -pedantic -ansi -lm -o test test.c
運行調試器:
gdb test
在控制檯輸入以下內容:
(gdb) break test.c:6
Breakpoint 1 at 0x400578: file test.c, line 6.
(gdb) r
Starting program: /home/pdedecker/Desktop/test
Breakpoint 1, main() at test.c:6
6 printf("sqrt(3): %f\n", sqrt(3));
(gdb) print sqrt(3)
$1 = 0
(gdb) s
sqrt(3): 1.732051
我的GDB版本爲GNU gdb (GDB) SUSE (7.1-3.12)
。
向我們展示您用來獲取此結果的代碼。 – birryree 2011-02-25 20:59:44
您是否包含''? –
2011-02-25 21:02:02
+1 Jeremiah,我記得我也面對那個錯誤的老年人:) – 2011-02-25 21:03:04