12 ms·
64-bit bank balances ‘ought to be enough for anybody’?
- Waterluvian 3y agoI’m a bit surprised that these two concepts are seen together. I’d of thought that financial math and data management would always be done with some level of abstraction so it doesn’t matter at all what your computer’s implementation is. Then again, 128 bits is plenty for microcents or whatever the minimim unit is. I’m guessing back in the day when things were 32 bit or less, there were entire financial database implementations that handled this abstraction?
- dboreham 3y agoHandled in hardware on some machines (e.g. VAX)
- DamonHD 3y agoIf you actually want to do something useful and accurate and auditable and performant and space-efficient, because you have a lot of money values to bank with, you really don't want too much abstraction. My experiences in various bits of banking include where juniors ignore advice NOT to store currency in floating point values and then come whining that arithmetic is broken, and tech dudes in a lab deciding that every single FX flow in an investment bank should have 2MB of (unshared) calendar hidden inside its abstraction which made some individual trades too big to load even for powerful machines... Fixed point calcs in integers are good.
- Waterluvian 3y agoFloating point feels like an incredibly grokkable concept that was just not taught well for a long time. Maybe too mathematically (of course). Or maybe that was just my experience. I feel like any dev team should pick up a copy of this for on-boarding: https://jvns.ca/blog/2023/06/23/new-zine--how-integers-and-floats-work/ https://jvns.ca/blog/2023/06/23/new-zine--how-integers-and-f...
- fidotron 3y agoFloating point being grokkable doesn’t make it any more suitable for this application. Floating point is inherently an approximation - your bank balance should not be an approximation.
- DamonHD 3y agoMore to the point binary fp absolutely is a bad approximation to, and does poor arithmetic on, common legal sub-1 decimal currency values, ie those that do not have an exact binary fp representation.
- Spivak 3y ago> Floating point is inherently an approximation - your bank balance should not be an approximation. I think this is a perfect example of bad floating point teaching. Floating point is not an approximation in any sense. If the numerical result of your calculation is representable in floating point you will get an exact answer always. And for results that aren't representable you decide exactly what should be done about that. It's like saying integers are an approximation because 5/2 == 2.
- deleted 3y ago[deleted]
- dahfizz 3y agoIn programming, an `int` perfectly represents the integers between INT_MIN and INT_MAX. A `float` on the other hand, approximates the real numbers. It can perfectly represent exactly 0% of them. Having control over the rounding behavior is meaningless - floats cannot correctly represent any non-contrived calculation. Exact representation is important in financial systems.
- fidotron 3y agoTBF, be careful here. The IEEE floats can represent a subset of integers in their range exactly. For example, 64 bit floats can represent the range of 32 bit ints accurately (and more). That said, it is bizarre to claim that if the result can be represented you get the exact result, when the core problem is that the result cannot be represented because the representation is an approximation.
- shortrounddev2 3y ago> I’m guessing back in the day when things were 32 bit or less, there were entire financial database implementations that handled this abstraction? This issue is what COBOL was designed to solve. Fixed decimal point arithmetic in base 10
- dahfizz 3y ago> be done with some level of abstraction so it doesn’t matter at all what your computer’s implementation is. This still doesn't do that, its just integer math. It doesn't matter how your CPU implements it, as long as `x = a + b` gives the correct value for x. You don't have to immediately reach for an abstraction layer when you hear the word "bits" ;)
- Waterluvian 3y agoBut without a sufficient stratigraphy of abstractions, I can't ever dig down if I run into issues! ;)
- Etheryte 3y agoPerhaps I'm the odd one out here, but most financial systems I've had the chance to work with don't actually use numeric types to store values, they use strings or other comparable types. Numeric values are passed to all outside interfaces, but the internal states are written in a way where no bit level issues peddle with the values. I'm wondering what the experience of the wider audience here is?
- alexvitkov 3y agoIf by "bit-level issues" you mean bit flips (which you should be worried about), a string doesn't help much - "4" is 0x34 ASCII/UTF-8, flip lowest bit and you get "5" (0x35). I'd imagine if I have to protect against bit-level fuckery something like this would be a better representation: struct Dough { u64 amount; u64 amount_again; u64 amount_just_to_be_really_sure; } that and hardware-level protection of course
- rvnx 3y agoStoring the same element the same way isn't really helping against implementation bugs, if going that route, better store in multiple formats (u64, int, or string), to protect yourself from a CPU or interpreter or library bug. In practice, just store the amounts as integer, and if you are really worried, add a checksum (if total balance is not enough).
- DamonHD 3y agoThat pretty much guarantees being the victim of multiple coding bugs...
- alexvitkov 3y agoMaybe, if you're an incredibly bad programmer. Add operator overloading and method to extract the number and you never have look at the internals again.
- GTP 3y ago
- jgalt212 3y agoAn argument over fractional pennies costs full dollars of peoples' time. - Anonymous
- throw0101c 3y agoI was under the impression that BCD was generally recommended for money, often because of (IEEE?) rounding and machine precision/epsilon: * https://en.wikipedia.org/wiki/Binary-coded_decimal https://en.wikipedia.org/wiki/Binary-coded_decimal * https://en.wikipedia.org/wiki/Machine_epsilon https://en.wikipedia.org/wiki/Machine_epsilon
- kawhah 3y agono, integers are generally used. BCD is fixed-point in any case so it's just an inefficient integer representation.
- iamds 3y agowhy add the complexity of bcd when you can just put in it units (e.g. cents) where there's no decimal point?
- 8organicbits 3y agoWhat do you do if heavy deflation causes the government to release a $0.001 coin? A cent isn't a fundamental unit. Edit: as another hypothetical, what if the $0.001 coin is released to support micropayment use cases?
- dahfizz 3y agoThese systems use something like 10^-8 as the implied decimal in the real world. Some forex exchanges even go to 10^-9
- out_of_protocol 3y agoFiat currency can go to -4 i think, crypto currency going to -18. And that's whole units like cents P.S. crypto things are using uint256 internally, and this type don't exist in most languages. Using int64 can work out, sometimes, and will usually break soon enough
- circuit10 3y ago
- belter 3y agohttps://www.joda.org/joda-money/ https://www.joda.org/joda-money/
- onetimeuse92304 3y agoSpecialising in financial software, over the past 2 decades I have been fighting over this with countless people, teams and companies. For accounting you should only ever use arbitrary precision math library with ability to specify rounding rules. If your programming environment/language does not have one, it is unsuitable to be used for accounting, billing, invoicing, payments, etc. Having the underlying library is, of course, not enough. You also need to be able to properly store (data structures, databases), transfer (wire formats, data structures), process (order of operations, rounding rules), present (UI toolkit) and so on. I have never in my life joined a software project for any organisation that was able to do basic arithmetic on money correctly (and I worked for companies ranging from small startups just needing invoices and very simple billing to risk management departments for largest financial institutions on Earth processing trillions of dollars on a daily basis).
- forinti 3y agoI have a personal anecdote on this subject. A long time ago I worked at a bank and I had to calculate a large number of accounts regarding agricultural loans. These were state sponsored loans. When I finished my task (this was a Java job), I found that sometimes the results were off by $0.01. So I asked my boss how I should do the rounding, to which he replied that an error of up to $1 was acceptable. If I recall correctly, the amounts where in the hundreds and thousands.
- rvnx 3y agoI had such case too, the solution is simple: round in favor of the bank / financial institution you are working for
- onetimeuse92304 3y agoNo, it does not work this way. Any good accountant will see a different in values, even smallest one, as a sign of an incorrect calculation. Does not matter which way it goes, they will feel compelled to figure out who is wrong. At least a good accountant will.
- matt3210 3y agoAt some point denominations will be 2^20 USD per note. As inflation grows, in the USA and others, a 64bit won’t be enough. Money is imaginary store of value we all agree on. The actual number changes.
- mbg721 3y agoWouldn't we just re-base the currency at that point?
- jon-wood 3y agoThat “just” is doing some very heavy lifting. That could potentially involve having to update almost every financial system worldwide given the US dollar’s position as a global reserve currency.
- mbg721 3y agoYes, but I think a "new dollar" is more likely than the US putting up with million-dollar bills. I guess it's a tough call which one is more embarrassing.
- ben_w 3y agoIf inflation averages 5% per year, a factor of 10^17 (what are the biggest USD notes actually in use?) is just over 800 years away, which is far enough that we might legitimately not have a moon any more let alone dollars. If hyperinflation brings that date closer, the dollar will probably also stop being a global reserve. Or possibly: will be caused by it ceasing to be a global reserve.
- Izkata 3y agoThe federal reserve aims for 2% a year, their adjustments just haven't been working.
- feoren 3y ago> 800 years away, which is far enough that we might legitimately not have a moon any more Wait, what? 800 years is absolute peanuts for the fate of orbital bodies. Wikipedia's Timeline of the Far Future estimates the demise of the moon in 7.59 billion years; still in orbit around the Earth (albeit a much higher one), it gets destabilized by the expanding sun and eventually swallowed by it, along with the Earth. If they aren't swallowed by the sun, they estimate 65 billion years before we lose the moon in one way or another. https://en.wikipedia.org/wiki/Timeline_of_the_far_future https://en.wikipedia.org/wiki/Timeline_of_the_far_future
- a-french-anon 3y agoReminds me of the Rosetta page https://www.rosettacode.org/wiki/Currency https://www.rosettacode.org/wiki/Currency for various ways to handle a related problem.
- deleted 3y ago[deleted]
- olalonde 3y agoStill not enough for storing Ethereum/ERC20 balances (256-bit)... :(
- Shrezzing 3y agoThe hyperinflation example is quite interesting because: 1) If it happens, it happens rapidly, and you don't want to implement this in a hurry 2) If it happens, the global economy could well be melting down, and your financial institution will have other priorities to attend to 3) Retaining existing staff, and hiring new engineers, will be challenging at best You really don't want to be implementing this change in those circumstances.
- runeks 3y agoI think it's the worst example. I very much doubt we will ever see the price of, say, a car approach a billion billion dollars (or cents). It's too many zeros for people to work with on a daily basis. I think what will happen is that, at regular intervals, the old hyper-inflated currency will be replaced with a new currency that's, say, 2^32 times less than the original one. Besides, if you think a billion billions might be reached (64 bits) then why wouldn't a billion billion billion billions also be reached (128 bits)? 128 bits seems just as arbitrary as 64 bits in this context.
- jefftk 3y agoBefore 2009 would you have predicted that a 100 Trillion Dollar bill would never be issued by a central bank?
- RandomLensman 3y agoGermany had notes and stamps in the trillions Marks in 1924 - nothing new there
- ilyt 3y ago2^63 / 100 Trillion = 9.2E6 so even in this case you have few decimal positions left.
- zarzavat 3y agoYou may be overlooking the potential for someone to own more than one of those $100T bills. Apparently it was worth about 30 USD at the time.
- perihelions 3y agoI see your 10^14 Zimbabwe Dollar Note and raise you this 10^20 Hungarian pengő, https://en.wikipedia.org/wiki/Hungarian_pengő https://en.wikipedia.org/wiki/Hungarian_pengő (caption: "100 million trillion (100 quintillion) pengő (1946)") At its nadir (US$ 1.0 = 4.6*10^29 P), a reasonable-sized transaction denominated in, for example, micro-pengős, would have overflowed a uint128_t. Conclusion: just use floating point, it's inflation-proof.
- throe37848 3y agoYou need to be also handle "origin" or "flavour" of money. Future governments may place various sanctions and limitation on money. So green dollars will be better, Russian dollars not so great and so on. Some money may be owed to local VIP, and should not be confiscated... All that may be mixed on single bank account.
- jorangreef 3y agoYes, we do also have various user_data fields for accounts/transactions to record the: who / when / where / why / what / how / how much https://docs.tigerbeetle.com/reference/transfers https://docs.tigerbeetle.com/reference/transfers
- lnxg33k1 3y agoWe could also tax everything above 32 bits, good for people, good for machine
- jkestner 3y agoImagine if the most money you could have is $43 million (rounding!), and it rolled over to 0 if you exceeded that. You'd be paying accountants to keep you as close to the limit as you dare, instead of just cheating on taxes. But not paying them too much, as you're only a multimillionaire.
- kardianos 3y agoIt sounds like they use a rational number with a fixed power of 10 denominator. Much like if they used Go's *big.Rat type with a fixed denominator of say 100 or 100000 depending on the currency, then the numerator they are moving from a 64 integer to a 128 bit integer. I personally don't see the advantage this has over a decimal 128 numeric value. In either situation, if you have 10 / 3, you will get 3.33 and need to round. Ultimately, the math concepts in finance are different then in abstract math. If for some reason you need to divide $10 by 3, it should result in three numbers: 3.33, 3.33, and 3.34. But fundamentally, I don't see how their fixed integer math fixes something as fundamental as that, over a standard decimal 128 representation.
- rbatiati 3y ago> If for some reason you need to divide $10 by 3, it should result in three numbers: 3.33, 3.33, and 3.34 Exactly! We don't try to "fix this math problem"; instead, we just want to reduce the surface area by using plain integers instead of decimal floating points.
- netheril96 3y agoETH uses 256-bit integers for accounting.
- sambeau 3y agoI once worked on a banking terminal for a large bank. My first attempt was sent back as there wasn't 'enough zeros on the buy button'. It could do £999,999,999
- karg_kult 3y ago[flagged]
- keepamovin 3y agoReserve Bank of Zimbabwe "100 Trillion Dollars" hahahahaha LOL. Is that real? OMG, that's incredible. Image if this trend kept going: what sign of humanity that new SI units need to be minted first because inflation drives currencies to insane new denominations, rather than cat videos, IoT and porn bulge yottabytes out of bounds?
- ceejayoz 3y agoZimbabwe underwent a period of hyperinflation. https://en.wikipedia.org/wiki/Hyperinflation_in_Zimbabwe https://en.wikipedia.org/wiki/Hyperinflation_in_Zimbabwe They eventually stopped printing currency.
- halosghost 3y agoA reminder that this still isn't the correct way of handling money. The correct way is to put it in the type-system [1]. All the best, -HG [1] https://web.archive.org/web/20211014094900/https://ren.zone/articles/safe-money https://web.archive.org/web/20211014094900/https://ren.zone/...
- runeks 3y agoThis only puts currency codes in the type system; and uses rational numbers for amounts. This is definitely useful because you can have the type system tell you if you've implemented e.g. exchange rate conversion incorrectly. But it's also a hassle because you need to reify currency values discovered at runtime as types, which isn't pretty [1]. [1] https://github.com/runeksvendsen/order-graph/blob/eef0006cba7aea019611063d648b0e9915644820/src/OrderBook/Graph.hs#L49-L64 https://github.com/runeksvendsen/order-graph/blob/eef0006cba...
- jorangreef 3y agoYes, and to your first point, TigerBeetle also supports multiple ledgers, explicitly where each ledger is for a separate unit or currency (with isolation enforced by TigerBeetle across different units/currencies). Thus, TigerBeetle doesn't preclude the use of money types at a higher layer (you would have seen that we tried to emphasize this also in the post). Another way to think of this, is that we focus on the storage of accounting information by providing high-performance accounting primitives (e.g. execute 8k double entry transactions all within 5ms in a single network roundtrip DB query). But the accounting policy (rounding etc.) remains the responsibility of the application/organization, since this may differ according to requirements/jurisdiction.
- mk_stjames 3y ago"All right, so when the subroutine compounds the interest, it uses all these extra decimal places that just get rounded off. So we simplified the whole thing and we just... we round them all down and just drop the remainder... into an account that we opened."
- jorangreef 3y agoGlad you enjoyed the reference!
- tech_ken 3y ago>Surprisingly, we also don’t use negative numbers (you may have encountered software ledgers that store only a single positive/negative balance). Instead, we keep two separate strictly positive integer amounts: one for debits and another for credits. It's funny I've always thought of two-column bookkeeping as a kludge that was invented because the author was unaware of negative numbers. But here there's actually a justifiable technical reason why they're superior (in this specific context)! History is a silly thing
- Jabrov 3y agoHow are they superior though? What do they gain by doing this (other than added complexity)?
- jorangreef 3y agoHey! Joran from TigerBeetle here. (I know this only because I somehow happened to major in Accounting back in university), but when you represent a general ledger of accounts, there are always two positive columns for amounts in any given account, one for debits, the other for credits. The golden rule is that you always add to either column. You always preserve information. To see why two columns (or two integer balances) preserves more information, take this example: 1. An account A with a debit balance of $1m and a credit balance of $1m, and 2. An account B with a debit balance of $0 and a credit balance of $0. Account A contains volume information in that you can immediately see not only that account A was transacted against, but with significant amounts. Conversely, account B shows no volume. But it's also clear even that there were no transactions between A or B. Whereas, if you take the net of the two amounts, and reduce that to a single amount in storage (as opposed to only taking the net in presentation), and if you use negative numbers, you lose this information. It's a subtle thing. The other angle here, is to consider why some engineers shortcut to negative numbers in the first place. I find that it's usually because they haven't fully grokked that accounting is itself a type system. You get assets, liabilities, equity, income and expenses (as account types), and the debit/credit balances, when considering the type of an account, tell you further information. For example, did a bank account suddenly transition into overdraft? Different account types, increase on different sides. I think this is also the reason that you find accountants typically wrapping amounts in parentheses, and then specifying the DR or CR side (or type of account), rather than using a negative sign. It's a tradition of preserving information.
- schmichael 3y agoI find the “no negatives” very confusing even in a double entry ledger for reasons the last sentence of that paragraph hints at: > When you need to take the net balance, the two balances can be subtracted accordingly and the net displayed as a single positive or negative number. This means you have to reconcile credits and debits using a different type than each of the columns is in. Not a huge deal by itself, but now that secondary type has to be a weird 129 bit integer (or larger) to ensure it can represent every intermediate sum of credits and debits. If they just would have sacrificed 1 bit they could have used a single signed 128 bit data type for all storage and computation. I suspect they have to enforce the “all debits and credits are positive” invariant in a number of places anyway (or risk coercing a negative signed 128 input into an unsigned 128 but ledger entry), so why not sacrifice a bit that will probably never be used otherwise anyway and have a uniform structure for numeric types?
- feoren 3y agoUsing a single signed 128-bit integer does not solve this. What happens when you have to add two of these together? Do you need a 129-bit signed integer? What about if you need to add 64 of these together; do you need a 134-bit signed integer? The point is that 128 bits is well large enough to hold the sum of quadrillions of transactions in Zimbabwean dollars. Nobody is switching to a 129-bit number to hold the results of sums; they are explicitly not handling the case where any account is anywhere close to 10^38 of the base unit.
- jorangreef 3y agoYes, we could have explained this more! (Joran from TigerBeetle here) The motivation is to preserve information, and I think this becomes less confusing once you understand that accounting is in fact a type system. I hope this comment makes this more clear: https://news.ycombinator.com/item?id=37571942 https://news.ycombinator.com/item?id=37571942
- atharv37 3y ago'hi"
- undersuit 3y agoMan, reminds me of my first work project, we rebuilt the time clock in 2006 for our department. I knew about inaccuracies in floating math so I thought I was taking precautions, but in the end my first native PHP float implementation introduced enough drift in just the hours field that we'd lose $40 a year. Rebuilt for the Decimal object and it lasted long enough until the entire organization bought it's own COTS solution. Now I'm trying to remember if I watched Office Space before or after...
- xhkkffbf 3y agoAnd the Fed says, "Hold my beer!"
- weinzierl 3y agoI once argued for using BigDecimal instead of Doubles in an invoicing software but had a hard time to come up with a practically relevant example. Is there an example where it makes a noticeable difference (at least one cent in the final result) that does not involve unrealistic amounts or numbers of items? I'm not arguing for Doubles, just collecting arguments to convince.
- crazygringo 3y agoI'm curious about this too. If you were engaged in millions of arithmetic operations then I can see how inaccuracies might accumulate in theory, but in practice floating point operations are intentionally designed to minimize that. And for everyday individual transactions it's hard to see a problem. Maybe the problem is more when you're summing up every single financial transaction for the year? But even in that case, if the smallest financial resolution is a cent, all the floating point noise seems like it would be occurring many decimal points beyond. Even if you're dealing with billions of dollars. To be clear, I wouldn't do it myself -- I'm too risk-averse, too afraid of unknown unknowns. But it is hard to see what actual real-life negative consequences there would be for 99.9% of businesses, unless I'm missing something? Like the parent commenter, I'm looking for where I'm wrong here.
- bob1029 3y agoThe part of using float for this that concerns me is not epsilon. It is all of the other weird edge cases & states. I don't like that 2 flavors of infinity and something that isn't a number are explicitly representable.
- dvlsg 3y agoTechnically you can have noticeable differences before you even make it to 1 cent. For example, if you're trying to determine if a result of a calculation is negative, 0, or positive for whatever reason. With floats/doubles, you would probably need to consider "0" to actually be "a number sufficiently close to 0, if not 0 exactly" and then remember to handle that everywhere. It can also be noticeable if you're just trying to calculate something like "is the invoice paid off". Maybe your view layer is showing $0.00 balance to the end user, but the backend hasn't correctly rounded off those extra bits from a floating point calculation, so your backend logic is now saying the invoice is not actually fully paid off, even if the end user has no idea what they could possibly still owe.
- zephyrus76 3y agoIt's interesting that even the current financial system fits so snugly into 2^64! Global GDP = $100T = $10^14. If we imagine global assets being worth 10x GDP, that's $10^15. 2^64 = 1.8 * 10^19. If people care about measuring values to precision at $0.0001, that's about the limit.
- walnutclosefarm 3y agoI'd like a report back from TigerBeetle on how many applications they actually support where the high order 64 bits are nonzero. I would note that the entire US GDP is less than 10^15 cents, and that 2^64 accommodates just shy of 10^19 in signed integers. So, even if your database had a justification for thousands of a cent transactions (not intermediate results, but recordable transactions), you'd still need to have transaction entries larger than the US annual GDP to roll over into the high order 64 bits. TigerBeetle may have made the right choice for some market, but I predict that there are vanishingly few sales calls where this becomes an important selling point, unless it's potential customers wondering why they are wasting all those bits and checks for a whole lot of freakin' zeros.
- jorangreef 3y agoTo be fair, I used to think like this too, but chatting with multiple large exchanges/brokerages made us realize this was a thing. > less than 10^15 cents There are systems that don't work in terms of cents (cf. the examples of issues in many of the comments here), or even in thousandths of a cent, but with significantly more precision. Literally, in other words: Where you run into problems then, with 10 ^ n integer scaling, is when n is large. When n is large, you aren't left with sufficient room in the remaining bytes to represent the whole-number part. In trading systems, for instance, you can easily hit 10 ^ 10 to represent fractional traded prices. Concretely, if you need to scale by 10 ^ 10, then your whole-number part is 2 ^ 64 / 10 ^ 10 = 1,844,674,407, which isn't terribly large.
- hot_gril 3y agoWhy do exchanges use such high precision for fractions?
- jorangreef 3y agoTo represent prices that are traded fractionally.
- 3y ago
- Animats 3y agoNext, people will want 128-bit/128 bit rational arithmetic for money. Then fractions will work right.
- jorangreef 3y agocf. https://news.ycombinator.com/item?id=37573939 https://news.ycombinator.com/item?id=37573939 (TLDR: It's the 10^10 precision in trading systems that gets you.)
- bsder 3y agoThe only good thing that Bitcoin ever did was create a real world use case that breaks shitty software handling financial numbers. Either the programmers have to do the right thing or tell their boss that they can never support Bitcoin. Both options give me a warm, fuzzy feeling inside when I watch them in real time.
- MagicMoonlight 3y agoIntel should release a new premium CPU with AccountMax Cores (just add a few registers for 256 bit math) Of all the problems to solve, the size of the registers is the most trivial.
- hot_gril 3y ago> For the same reason, digital currencies are another use case for 128-bit balances, where again, the smallest quantity of money can be represented on the order of micro-cents (10-6)… or even smaller. To give a concrete example, Ethereum has a lot of precision (1 ether = 10^18 wei), and there are like 120M ether, so that's more than 64 bits just to represent the supply. Idk though, is this a real concern with traditional finance? Zimbabwe had their huge bills, but I assume the small ones were unused. Just like you round US cents, you could probably round their currency at some cutoff. If you were processing Ether outside the blockchain like just some other currency, you'd probably round somewhere too. If you look at Stripe's API for example, they do everything with fixed-size (JSON's 53-bit) integers defined as cents or whatever.
- JeremyNT 3y ago> Idk though, is this a real concern with traditional finance? Zimbabwe had their huge bills, but I assume the small ones were unused. Just like you round US cents, you could probably round their currency at some cutoff. If you were processing Ether outside the blockchain, you'd probably round somewhere too. Yeah... I started reading this article and was waiting for the crypto angle, because in normal finance I don't see how it could plausibly matter (disclaimer: not my domain). The only reason I could imagine needing to track this level of precision on fractional units of currency was the sort of financial trickery that is enabled by cryptocurrencies.
- hot_gril 3y agoEven in cryptocurrency, I feel like the level of precision is mainly aspirational + cuz they can. Who cares about 1 wei in the context of a transaction that costs around 100 trillion wei on its own? The smallest unit of ether I've ever seen in any kind of UI is 1 gwei (1 billion wei).
- hot_gril 3y agoForgot to also add, cause various parts of a cryptocurrency ecosystem are much harder to change than traditional finance. So I can see why they throw in a ton of 0s and use 256-bit ints just in case.
- cryptonector 3y ago> While some may argue that a 64-bit integer, which can store integers ranging from zero to 264, is enough to count the grains of sand on Earth, we realized we need to go beyond this limit if we want to be able to store all kinds of transactions adequately. 64-bit integers are barely enough anyways. If the world-wide patrimony is somewhere near $100tn or $200tn, that's around a bit more than 10^16 (so let's round the exponent up to 17) cents, and that's just two digits short of the maximum that can be expressed with 64-bit signed integers! If you want to sum things like inter-bank debt, or if we have a lot of growth or hyperinflation we might need to express between 1¢ and $1e18 or $1e19, but the max range with signed 64-bit integers is [-$9.2 x 10^18, $9.2 x 10^18] if we still need to represent cents. So 64 bits is starting to be a tad too small for financial purposes. Even unsigned 64-bit integers are not that comfortable, but signed integers are needed if you're dealing with assets and liabilities. 128-bit is definitely too big, but it's a lot easier to deal with than variable-length integers. One might still use variable length encodings to save space on the wire or on disk, but in-memory 128-bit integers is the way to go.
- lr1970 3y agoFundamentally, the problem of representing money as Integers is division. A set of integers is not closed over division and, as mathematicians would put it, set of Integers does not form a field. For example, 10/3 is not an integer. Making fundamental money unit small does not solve the problem, it simply limits the size of rounding error. Division followed by multiplication can amplify the rounding errors. A clean solution would be to use rational numbers of the form y/x stored as a pair of 64-bit numbers. It takes the same 128-bits space as in TigerBeetle proposal but has advantage of exact arithmetic with no rounding errors. EDIT: typos
- imtringued 3y ago>This not only avoids the burden of dealing with negative numbers (such as the myriad of language-specific wraparound consequences of overflow… or underflow), Is this supposed to be some kind of joke? Unsigned underflow wraps around to the highest number. Meanwhile signed gives you a negative number, which tends to be properly handled by code that assumes positive numbers.
- NikkiA 3y agoI despair at the state of CS these days.