3 ms·
The only real correct solution here is to send mantissa and exponent as two separate integers. It's trivial to convert between exponents for whatever math you w
by noitpmeder 3mo ago
The only real correct solution here is to send mantissa and exponent as two separate integers. It's trivial to convert between exponents for whatever math you want, it can be as correct as you want, and is unambiguous.
In the HFT space you save some wire space if you can commit to a consistent exponent for some {slice} up front (think instrument/tick-size/asset-class/exchange/feed/server/whatever/...) such that you only need to send the mantissa and your clients can have a hard coded exponent. However, in similar spaces it's often worth the extra uint32 to send a on-the-wire exponent such that things _can_ change and you aren't hamstrung later by earlier "we only need cents now!" design choices when, e.g., you suddenly need to support bitcoin/... prices to full precision. (your users will thank you when they don't have to coordinate a breaking change when you want to adjust your fixed exponent)
- microgpt 3mo agoIf you do that though aren't you just reinventing floating-point?
- jjmarr 3mo agoNo, because you're doing decimal floating point, which eliminates the rounding errors of binary floating point.
- IshKebab 3mo agoThey're both floating point. https://en.wikipedia.org/wiki/Decimal128_floating-point_format https://en.wikipedia.org/wiki/Decimal128_floating-point_form... What noitpmeder described is just floating point.
- OtherShrezzing 3mo agoNo, standard floating point implementations have higher precision for smaller numbers than larger. So for example, in a 32bit float, there are far more numbers between 0-1 than there are between 1,000,000 and 1,000,001. For 32bit floats, you start lowing whole integers with relatively small numbers. Integers have a consistent precision across the entire number line.
- lxgr 3mo ago> The only real correct solution here is to send mantissa and exponent as two separate integers. That’s essentially the same thing as a String-serialized big decimal, just less readable, no?
- gmm1990 3mo agoThat’s quite a bit slower to process. At least if you’re converting to integers to do the calculations and the calculations would be quite a bit slower if you kept the big decimal type
- lxgr 3mo agoTrue, but this is usually your least concern when you're dealing with monetary amounts/math.
- mnahkies 3mo agoThey specifically mentioned HFT so I suspect they care a lot about processing speed
- Maxatar 3mo agoIt might be your least concern, and that's fine but it's not the least concern for many people who need to process large volumes of transactions. Money, even within fintech, is a concept used across a wide variety of domains, and you can't assume that what concerns you is what concerns everyone else relying on it elsewhere.
- gmm1990 3mo agoI guess I’m coming at it from an optimizing market data provider perspective once you preallocate memory the next thing to optimize is the string decimal conversion if the feed isnt binary encoded