Live data from Hacker News

64-bit bank balances ‘ought to be enough for anybody’?

tigerbeetle.com

361–370 of 372 posts

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#361
post #337

Earlier quoted context omitted.

That’s not a problem by itself. You can represent 0.3 as 0.300000…0004, which rounds to 0.3 again in the end. But you need to reason about the number and nature of intermediate operations, which is tricky, since errors usually accumulate and don’t always cancel out.

> That’s not a problem by itself. No, it really is the original sin here. > since errors usually accumulate and don’t always cancel out. The problem is that from the system's perspective, these aren't "errors". 0.3000000....4 is a perfectly valid value. It's just not the value that you want. But the computer doesn't know what you want.

> The problem is that from the system's perspective, these aren't "errors".

When I say "error" here I mean the mathematical term, i.e. numerical error, from error analysis, not "error" as in "an erroneous result".

There is a formalism for measuring this type of error and making sure it does not exceed your desired precision.

> It's just not the value that you want.

My point is exactly that if you're looking at 0.300000...4, you aren't done with your calculation yet. If you stop there and show that value to a user somewhere (or are blindly casting it to a decimal or arbitrary precision type), you are using IEEE 754 wrong.

You know that your input values have a precision of only one or two sub-decimal digits, in this example, so considering more than ten digits of precision of your output is wrong. You have to round!

It's the same type of error that newspapers sometimes make when they say "the damage is estimated to be on the order of $100 million (€93.819 million)".

Yes, this is often more complicated and error-prone (the human kind this time) than just using decimals or integers, and sometimes it will outright not work (since it's not precise enough – which your error analysis should tell you!)! But that doesn't mean that IEEE 754 is somehow inherently not suitable for this type of task.

As a practical example, Bitcoin was (according to at least one source) designed with floating point precision and error analysis in mind, i.e. by limiting the domain of possible values so that it fits into double-length IEEE 754 floating point values losslessly – not because it's necessarily a good idea to do Bitcoin arithmetics using floating point numbers, but to put bounds on the resulting errors if somebody does it anyway: That's applied error analysis :)

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#362
post #293

Earlier quoted context omitted.

> That depends on whether the hundred-billion-dollar corporation cares about being off by a dollar. How many hundred billion dollar corporations are private? Public companies would care a great deal about accounting accuracy.

Is it worse for a hundred billion corp to be off by a dollar than for a hundred million corp to be off by a third of a penny?

If they could just pay the dollar and never have to worry about it again, sure. But the point is for them to have confidence that the math is unimpeachable and identical to whatever auditor or tax official would compute at every step of the way so you don't just have to guess at correctness with some waving of hands.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#363

Earlier quoted context omitted.

I'm going through this pain right now in helping my kid with homework in rounding and discovering my internalized rules are different from what they're being taught now. EXACT same pain as yours, depending on the precision and rounding rules of your pain scale.

Less than four rounds down to zero, five and above rounds up to 10. What has changed? Or how different were your internalised rules?

Round to the even number, which eliminates a bias toward the higher number. This is the way Python does it.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#364

Earlier quoted context omitted.

You 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.

If $100T = 30 USD, then probably nobody will mind if we round to the nearest $1B. Just like how I have no way to compensate someone for less than 0.01 USD.

The government cares, the precision necessary for taxes is sub cent as mentioned in some replies to the top comment on this post.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#365
post #14

Earlier quoted context omitted.

I have never encountered such a system. Integers used for fixed-point representation do not suffer from "bit-level issues".

Is fixed-point the right term ? As far as I know fixed point numbers have a fixed fractional part in bits, but this is different from using integers with a multiplicative factor, like 100, to represent correctly a fractional part as 1/100.

No it's not different, what you describe is exactly what fixed point is.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#366
post #13

Earlier quoted context omitted.

Not true for any of the finanical systems I've worked for the credit/derivatives/FI/etc desks of some of the largest investment banks down to the systems for the virtual card e-money issuer in the UK that I founded.

Derivatives are generally subject to some fairly large uncertainty in valuation, for example bid/offer spreads are usually many orders of magnitude larger than floating point error. When the derivative expires it does have some very fixed value but the investment bank will have made enough money off the trade to "generously" round up the float to the nearest cent.

Profit/margin was not larger than the ulp for single-precision float values for derivatives by the time I got there, so we all were using doubles.

The rounding-for-settlement issue that you describe is, I think, separate.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#367

Earlier quoted context omitted.

Is it worse for a hundred billion corp to be off by a dollar than for a hundred million corp to be off by a third of a penny?

it's not so much how much it is off but that it's off at all. If the numbers don't add up then they don't add up. If there's any kind of difference then it has to be found and accounted for and it becomes a needle in a haystack search to account for the difference. Think about trying to find $0.05 spread across hundreds of thousands of transactions due to rounding issues.

I'm going to let you in on a secret...

Every single publicly listed company, every single one of them, is off when it comes to calculating their taxes by way more than just a dollar. And I don't mean clever accounting tricks or tax avoidance schemes, I just mean in terms of actual mistakes being made.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#368
post #359

Earlier quoted context omitted.

> Oh, the business teams found the approach puzzling---but what do they know, right? If they were smart, they would be software engineers. Well in this case the business teams selected the 3rd party payments gateway that the company would work with, negotiated the contracts with them, and worked with the 3rd party to set up how the customers would be charged. They and/or the product team determined that we'd use the…

If someone had a gun to my head saying, don't hide the sub-penny slices from the billing, I would just do the billing in thousandths of a cent, rather than make "leap cents" appear every couple of bills: Amount owing: $123.45678 Please pay one of: $123.46 (a credit of $0.00322 will be applied) $123.45 (a balance of $0.00678 will carry forward) On the next statement, if they paid $123.46: Previous balance: ( $0.00322)…

> I would just do the billing in thousandths of a cent, rather than make "leap cents" appear every couple of bills

Again, that was not something we could control.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#369
post #305

Earlier quoted context omitted.

It's strange. In Russia, small error in VAT will get you a letter from tax service "pay us a small error voluntarily, or we will schedule an inspection". Letter will be automatically generated by ASK-NDS system (translated as Auto Check Vat).

How do they know there's an error?

Cross check with your contragents. For every bit of incoming VAT should be outgoing VAT from your supplier. And for outgoing VAT should be incoming VAT for your client and/or sale to physical customer.

If your incoming VAT are not matched with outgoing VAT from your supplier, you will be charged.

If your supplier declared VAT, but failed to pay it, you have choice: either you have to pay it or you will be inspected to proof that it was not a fake.

Every sale to physical customer in Russia should be uploaded to tax service cloud. You (as a customer) could check your receipt online or using app, and get a reward for reporting tax evasion.

This system boosted VAT revenue x1.5 in a few years.

Re: 64-bit bank balances ‘ought to be enough for anybody’?

#370

Earlier quoted context omitted.

I wasn't talking about rounding up. I meant exactly the same thing you're saying about month 4. > Because the bill included a detailed breakdown of all the fees by type and transaction. Was it all rounded [down] to the nearest penny? That type of bill can already fail to add up to the total very easily, like x.xx4 + x.xx4 + x.xx4. So I'm still not sure why there was a need to have a line item to explain this single p…

Canada abolished the penny some years ago. If some retail item in a store costs $2.03 and you insist on paying with cash, you will have to use a nickel and pay $2.05. Yet, life goes on; nobody goes to jail.

Generally such rules are only about cash, though.
Post reply on HN