【发布时间】:2019-09-08 03:12:19
【问题描述】:
如何在编译时将常量浮点值转换为十六进制?
在运行时我这样做:
int main()
{
union float_to_int
{
float float_;
int int_;
};
printf("43.2 in hex: 0x%X.\n", float_to_int{ 43.2f }.int_);
return 0;
}
如何在编译时做到这一点?我完全迷路了
【问题讨论】:
-
请注意您的代码是未定义的行为。
标签: c++ c++14 c++17 compile-time-constant