Most efficient standard-compliant way of reinterpreting int as float

后端 未结 4 1772
不思量自难忘°
不思量自难忘° 2020-12-13 18:20

Assume I have guarantees that float is IEEE 754 binary32. Given a bit pattern that corresponds to a valid float, stored in std::uint32_t, how does

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 19:14

    If the bitpattern in the integer variable is the same as a valid float value, then union is probably the best and most compliant way to go. And it's actually legal if you read the specification (don't remember the section at the moment).

提交回复
热议问题