Why the IEEE-754 exponent bias used in this C code is 126.94269504 instead of 127?

前端 未结 2 1648
被撕碎了的回忆
被撕碎了的回忆 2021-02-13 09:37

The following C function is from fastapprox project.

static inline float 
fasterlog2 (float x)
{
  union { float f; uint32_         


        
2条回答
  •  温柔的废话
    2021-02-13 10:23

    In the project you linked, they included a Mathematica notebook with an explanation of their algorithms, which includes the "mysterious" -126.94269 value.
    If you need a viewer, you can get one from the Mathematica website for free.

    Edit: Since I'm feeling generous, here's the relevant section in screenshot form.

    Simply put, they explain that the value is "simpler, faster, and less accurate".
    They're not using -126.94269 in place of -127, they're using it in place of the result of the following calculation (values rounded for brevity):

    -124.2255 - 1.498 * mx - (1.72588 / (0.35201 + mx))
    

提交回复
热议问题