GDB - 访问复数的实部和虚部

发布于 2024-10-10 06:23:07 字数 363 浏览 0 评论 0原文

调试使用(C 或 C++)的程序时,gdb 将复数显示为 _M_value = xxx + yyy*I(类型为 complex double< /代码>)。

在调试时,我需要打印该数字乘以一个因子。

以下不起作用

print a * 8.0

我得到算术运算的参数不是数字或布尔值

另外,我无法访问实部和虚部,因此我可以编写 gdb 宏来执行上述操作。我当前的解决方案是编写一个 C 函数来操作复杂值和数组,并从 gdb 调用该函数。不知何故,这感觉不太对劲。

When debugging a program which uses (either C or C++), gdb displays complex numbers as _M_value = xxx + yyy*I (with a type of complex double).

While debugging, I need to print that number multiplied by a factor.

The following does not work:

print a * 8.0

I get Argument to arithmetic operation not a number or boolean.

Also, I cannot access the real and imaginary parts so that I can write a gdb macro to do the above. My current solution is to write a C function for manipulating complex values and arrays, and calling that function from gdb. Somehow, this just doesn't feel right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

源来凯始玺欢你 2024-10-17 06:23:07

如果您使用标准 C++ 复杂模板,则complex::real() 和complex::imaj() 应该可以工作。

my2c

注:是一条评论 ^^

If you use the standard C++ complex template then complex::real() and complex::imaj() should work.

my2c

Note : Was a comment ^^

倾其所爱 2024-10-17 06:23:07

您可以调用 C 库函数 creal()cimag() 来分解数字。

You can call the C library functions creal() and cimag() to break down the number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文