简体   繁体   English

在GDB中指定浮点精度

[英]Specify floating point precision in GDB

I am debugging a C++ application and when I display a double-precision floating point number in GDB I get a result like: .035449094393 我正在调试C ++应用程序,当我在GDB中显示双精度浮点数时,得到的结果如下: .035449094393

How do I display more decimal places? 如何显示更多小数位? Ideally I would be able to specificy the precision and get a result like: .0354490943927692 理想情况下,我可以指定精度并得到如下结果: .0354490943927692

Basically, I am attempting to find the reason for a very minor difference between 2 variables. 基本上,我试图找出两个变量之间存在很小差异的原因。 If I use printf with a format specifier like %1.20f I can see the difference in the variables but not using GDB. 如果我将printf与%1.20f类的格式说明符一起使用,则可以看到变量的差异,但不使用GDB。

By default, GDB's p/f <variable> has limited precision. 默认情况下,GDB的p/f <variable>具有有限的精度。

You can use printf to show more decimal places: 您可以使用printf显示更多的小数位:

(gdb) printf "%1.20f\n", <variable>

However, it is very likely that at this point you will start running into the limitations of your data type (there may be rounding errors and other small deviations from what you might expect as a value). 但是,极有可能在这一点上您将遇到数据类型的限制(可能会有舍入错误和与期望值有关的其他小偏差)。

您可以在gdb call printf("%.10f\\n", d) ,它将以所需的格式在stdout进行打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM