I feel obligated to post a link to this excellent (albeit incomplete) writeup of posits and unums, which can more accurately represent common fractions in memory at the same (or lower) bit size compared to traditional floating point.
Said page also includes the single best slightly-above-entry-level explanation of how floating point works I’ve ever seen.
As far as I understand, it seems to sacrifice accuracy at larger numbers, for more accuracy at smaller numbers. As they say, that seems like a reasonable tradeoff, because we tend to mostly use smaller numbers in our software.
In my honest opinion though, if accuracy is a concern, I reach for decimal or integer based mathematical libraries. For example, in a JavaScript project that needed to handle currency, I used Dinero, because $0.1 + $0.2 needs to actually work properly. As far as I understand, it just does all math in integers, and then you can display it as a string in the UI or export it as an integer for storage as a realised decimal in the database.
i have so many protocols to represent the most common fractions perfectly without needing more than just ONE bit. They even work with positive and negative infinity!
The trick is to first negotiate the protocol youre using.
Can you explain how this works exactly? Do you mean you have like a “third type” or “fraction”: 3 and you just store 00 for 0/3, 01 for 1/3, 10 for 2/3, 11 for 3/3? If it’s an object, struct, or class type to store the context, then it’s not a primative and has a lot of overhead for arithmetic and I don’t see how you could possibly even do simple things like 1/3 + 2/6
Isn’t a big point of floating point that it can easily have mathematical operators done on them on CPUs? Sure, complex circuitry is no big deal these days, but IIRC, there were very good reasons for what was chosen.
One of the linked papers makes the claim that the circuitry would be less complex than that needed for floats, but also includes this note:
Floats have one advantage over posits for the hardware designer: the fixed location of bits
for the exponent and the fraction mean they can be decoded in parallel. With posits, there is a
little serialization in having to determine the regime bits before the other bits can be decoded.
There is a simple workaround for this in a processor design, similar to a trick used to speed the
exception handling of floats: Some extra register bits can be attached to each value to save the
need for extracting size information when decoding instructions.
The proposed system also lacks NaN and separate positive/negative infinities, so it wouldn’t be a drop-in replacement.
I feel obligated to post a link to this excellent (albeit incomplete) writeup of posits and unums, which can more accurately represent common fractions in memory at the same (or lower) bit size compared to traditional floating point.
Said page also includes the single best slightly-above-entry-level explanation of how floating point works I’ve ever seen.
As far as I understand, it seems to sacrifice accuracy at larger numbers, for more accuracy at smaller numbers. As they say, that seems like a reasonable tradeoff, because we tend to mostly use smaller numbers in our software.
In my honest opinion though, if accuracy is a concern, I reach for decimal or integer based mathematical libraries. For example, in a JavaScript project that needed to handle currency, I used Dinero, because $0.1 + $0.2 needs to actually work properly. As far as I understand, it just does all math in integers, and then you can display it as a string in the UI or export it as an integer for storage as a realised decimal in the database.
i have so many protocols to represent the most common fractions perfectly without needing more than just ONE bit. They even work with positive and negative infinity!
The trick is to first negotiate the protocol youre using.
protocol schema 1/2
1 bit, little endian
if one: value is exactly 1/2
If zero: value is NOT one half
Schema 1/3
if one: value is 1/3
I’ve managed to create a compression algorithm that reduces files down to a single bit. I call it “is this file ‘loss.png’?”.
It’s guaranteed 100% lossless with any input!
Reminds me of MetaGolfScript.
Can you explain how this works exactly? Do you mean you have like a “third type” or “fraction”: 3 and you just store 00 for 0/3, 01 for 1/3, 10 for 2/3, 11 for 3/3? If it’s an object, struct, or class type to store the context, then it’s not a primative and has a lot of overhead for arithmetic and I don’t see how you could possibly even do simple things like 1/3 + 2/6
is_half = True is_third = TrueIsn’t a big point of floating point that it can easily have mathematical operators done on them on CPUs? Sure, complex circuitry is no big deal these days, but IIRC, there were very good reasons for what was chosen.
One of the linked papers makes the claim that the circuitry would be less complex than that needed for floats, but also includes this note:
The proposed system also lacks NaN and separate positive/negative infinities, so it wouldn’t be a drop-in replacement.