Lua - packing IEEE754 single-precision floating-point numbers

后端 未结 2 707
野的像风
野的像风 2020-12-30 09:13

I want to make a function in pure Lua that generates a fraction (23 bits), an exponent (8 bits), and a sign (1 bit) from a

2条回答
  •  遥遥无期
    2020-12-30 09:17

    Multiply the significand you get from math.frexp() by 2^24, and subtract 24 from the exponent to compensate. Now the significand is an integer. Note that the significand is 24 bits, not 23 (you need to account for the implicit bit in the IEEE-754 encoding).

提交回复
热议问题