如何将uint64_t变量位重新解释为双精度,而不是static_cast


uint64 value = 0x543;
double dval = *reinterpret_cast<double*>(&value);

我希望dval是一个特定的值,当用十六进制写时,它看起来像这样";0x543";。这样做有危险吗?你认为有更有效的方法吗?

感谢

使用std::bit_cast。事实上,所示的例子正是你想要做的

最新更新