C99:使用 (+0 -0.0i) 初始化 _complex 变量的正确方法
在 C99 中使用 (+0 -0.0i)
静态初始化 float _complex
变量(实数中为正零,imag 中为负零)的正确方法是什么?
float _Complex a = _Complex_I * (-0.0); // this seems doesn't work
int main()
{
printf("a = (%f %f) \t(0x%016llx)\n",crealf(a),cimagf(a), *((long long*)&a));
}
附言。我需要静态初始化,所以不能使用
__real__ a = 0.0; __imag__ a = 0.0;
What is the right way to statically initialize float _complex
variable with (+0 -0.0i)
(positive zero in real and negative zero in imag) in C99?
float _Complex a = _Complex_I * (-0.0); // this seems doesn't work
int main()
{
printf("a = (%f %f) \t(0x%016llx)\n",crealf(a),cimagf(a), *((long long*)&a));
}
PS. I need a static initialization, so this can't be used
__real__ a = 0.0; __imag__ a = 0.0;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,确实没有一个。这就是 C 标准在 C1x 中包含
CMPLX
宏的原因。由于我相信您正在使用 GCC,因此您可能有兴趣关注此错误< /a>.特别是,如果您不介意生活在最前沿,您也许可以执行以下操作:(
有关更多详细信息,请参阅 4 月 28 日围绕 Jason Merrill 的提交进行的讨论)。我不确定,但您可能还需要提交一个单独的错误,请求在 C 前端支持此功能。
Unfortunately, there really isn't one. This is why the C standard includes the
CMPLX
macros in C1x.Since I believe that you're using GCC, you may be interested in following this bug. In particular, if you don't mind living on the bleeding edge, you may be able to do something like:
(see discussion around Jason Merrill's commit on April 28 for more details). I'm not certain, but you may also need to file a separate bug requesting support for this feature in the C front end.