简体   繁体   English

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

[英]GDB - Accessing real and imaginary parts of a complex number

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 ). 在调试使用(C或C ++)的程序时, gdb复数显示为_M_value = xxx + yyy*I (具有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 . 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. 此外,我无法访问实部和虚部,以便我可以编写一个gdb宏来执行上述操作。 My current solution is to write a C function for manipulating complex values and arrays, and calling that function from gdb. 我目前的解决方案是编写一个C函数来处理复杂的值和数组,并从gdb调用该函数。 Somehow, this just doesn't feel right. 不知何故,这感觉不对。

If you use the standard C++ complex template then complex::real() and complex::imaj() should work. 如果使用标准C ++复杂模板,那么complex :: real()和complex :: imaj()应该可以工作。

my2c MY2C

Note : Was a comment ^^ 注意:是评论^^

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

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

相关问题 是否可以使用C ++中的[]运算符访问复数的实部和虚部? - Is it possible to access the real and imaginary parts of a complex number with the [] operator in C++ 如何在CUDA中单独获取复杂矩阵的实部和虚部? - How to get the real and imaginary parts of a complex matrix separately in CUDA? 在C ++中获取指向复杂向量的实部和虚部的指针 - Getting pointers to the real and imaginary parts of a complex vector in C++ 如何提取复特征张量的实部和虚部? - How to extract real and imaginary parts of complex Eigen tensor? 如何有效地提取 Eigen3 库中复矩阵的实部/虚部? - How to efficiently extract real/imaginary parts of complex matrix in Eigen3 library? 将复数 object 与实部和虚部乘以 C++ 中“双”类型的乘数 - Multiply complex object with real and imaginary parts by a multiplier of type 'double' in C++ 有没有保证很复杂 <Type> 输入实数时,对象的虚部设置为零吗? - Is there any guarantee that complex<Type> object's imaginary part is set to zero when a real number is input? 如何转换推力复数矢量的虚部和实部 - How to switch the imaginary and reall parts for thrust complex vector C ++在虚部显示带i的复数 - c++ display complex number with i in imaginary part 如何在输出中获取带有&#39;i&#39;(虚值)的复数输出 - how to get output of complex number with 'i' (imaginary value ) in the output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM