Rocinante8
Rocinante8

Reputation: 13

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.

Upvotes: 1

Views: 49

Answers (0)

Related Questions