Lua - packing IEEE754 single-precision floating-point numbers

后端 未结 2 617
野的像风
野的像风 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).

    0 讨论(0)
  • 2020-12-30 09:29

    Have you seen this?

    I think it does what you want in a slighty simpler way.

    0 讨论(0)
提交回复
热议问题