‹ 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. tialaramex · · focus · HN ↗
      The 32-bit subnormals are all the non-zero 32-bit floating point values between but not including -0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625 and +0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625

      Does that help you?

      [Edited: correct decimal after noticing that my calculator defaulted to the wrong setting]

      [And again because I think there's a bug in the last few digits, so debugging that's a fun activity for the weekend]

      [And a third time because nope, those were correct and I can't type]

      1. nayuki · · focus · HN ↗
        Very interesting, you are right. The IEEE 754 standard defines positive/negative zero as not subnormal numbers.

        Mechanically speaking, the two zeros use the subnormal number format, so in that sense they are subnormal (but definitionally they aren't). Also, I guess FPUs treat zero differently from other subnormal numbers, which is why zero doesn't have a performance penalty.

        Relevant articles to read: <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;73890260&#x2F;why-is-zero-not-a-subnormal-number" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;73890260&#x2F;why-is-zero-not... , <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sterbenz_lemma" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Sterbenz_lemma , <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Subnormal_number" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Subnormal_number

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.