开发者

How to make a constexpr that equals -0.0

Any way for me to set a constexpr to negative 0?

A legacy library uses negative 0 to indicate the calculation failed so I want to create a constexpr float fNEGZERO = -0.0.

Normally I would create this using a union between a uint32 and a float and set the uint32 bits to 0x8000'0000. But constexpr doesn't allow having a union access the non-active member. In theory the compiler does the same thing for NaN, +Inf, etc. but looking at numeric_limits it seems like they rely on built in 开发者_如何学编程compiler values.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜