An unofficial, read-only Hacker News reader.

Beating Floating Point at Its Own Game: Posit Arithmetic [pdf] (opens external site)

56 points by xenophonf 5 hours ago | www.johngustafson.net | 20 comments on HN

View full thread · View on Hacker News

Comment thread (4)

  1. If you mean a software implementation, I would daresay my impl is actually pretty readable :) https://github.com/andrepd/posit-rust/blob/main/src/posit/op.... It's also the fastest I'm aware of (at least back when I was working on it).

    You do pretty much always have to convert to an intermediate representation of "mantissa + exponent". That is how IEEE754 impls work also. It is a bit more complex than IEEE to do so, because of the variable-length field, but surprisingly not too much so (count-leading-0 plus a couple of shifts and xors do the trick!) Less than 2ns on my machine :)

    Replies (1)
    1. It's effectively a "slide rule" numerical system so (to avoid intermediate representations) multiplication become addition and addition becomes softmax, right?
      Replies (1)
      1. I'm not sure what you mean by "slide rule" or "softmax" in this context :p but both binary IEEE and posits are essentially encodings of numbers of the form `(fraction / DENOMINATOR) * 2*exponent`, where `fraction` and `exponent` are integers and `DENOMINATOR` is fixed. The same general principles for implementing arithmetic operations apply for both.
        Replies (1)
        1. Oh boy, this is a fun one. :)

          Slide-rules are handy because they convert multiplication into addition. Or technically that's what logarithms do, and slide-rules are a physical implementation of logarithms.

          Recall the classic identity:

          log(x * y) = log(x) + log(y)

          Slide-rules have multiple rulers, and some are marked in log scale, which lets you multiply totally mechanically! By aligning the markings, you effectively add two lengths, which (when read back on the log tick marks) becomes multiplication.

          If you perform the same algebra transform as above, you see that addition becomes (oddly, but more intuitive the more you think about it) the Softmax function.

          https://en.wikipedia.org/wiki/Softmax_function

          This is my first time seeing Posits, but (having had similar ideas loosely inspired by the Doom bit-hacks) I just assumed this was one of the main sales pitches for Posits!