‹ BackHN Continuity

Thread

Subnormal floating-point numbers are expensive on Intel processors

69 points · 54 comments · zdw

  1. gwbas1c · · focus · HN ↗
    I'm still trying to understand what a subnormal number is; IE, I'm looking for the TLDR so I know just enough to know if I'm using them and need to learn more.

    Unfortunately, the Wikipedia article, while probably being accurate, doesn't give a clear and concise answer.

    IE, is 0.0001 a subnormal? Or is it 0.000000000000000000001?

    1. Someone · · focus · HN ↗
      That depends on how you store it.

      Each number can be written in infinitely many ways, for example 12, 1.2E1, and 0.012E3 all are “twelve”

      In (binary) IEEE floats, the canonical way to write floats is

        significant × 2^exponent
      
      with 1 ≤ significant < 2. So, “twelve” gets stored as 1.5 × 2³ and not as, for example, 0.375 × 2⁵, 12 × 2⁰ or 96 × 2⁻³.

      Float operations normally return numbers satisfying that.

      However, in IEEE, the exponent cannot be made arbitrary small. Because of that, some very small numbers cannot be represented that way.

      In those cases the standard says operations can return numbers with the value closest to the correct value with a significant less than 1. Those number representations are called subnormals.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.