5 ms·
Have you worked on finance software? I have - we always used ints for everything, so we could avoid rounding suprises
by jes5199 8y ago
Have you worked on finance software? I have - we always used ints for everything, so we could avoid rounding suprises
- bigiain 8y agoI did a web project in the gambling space ~10 years back - we were legally required to perform all calculations as integers in ten thousandths of a cent (or millionths of a dollar). We chose to _not_ do _any_ calculations client side in Javascript...
- dotancohen 8y agoWhich regulation is that? I've worked on financial applications, but not gambling, and I've not heard of this regulation. I should probably know about it!
- ajanuary 8y agoI worked for a gambling company in the UK for a bit. They did all their maths in pennies, not thousandths of a penny.
- bigiain 8y agoAustralian, or possibly Tasmanian state regs. This would have been around 2011 or so (The Samsung Galaxy S2 was the "top of the range Android phone" at the time...)
- DougBTX 8y agoI’ve not done any real finance programming, so is this a reasonable explanation? Currency is stored as a count of cents (millicents if being fancy). Therefore the two main features of floats are not useful: - Support for very small numbers is not needed. Floats dedicate approx half their range to numbers between -1 and +1, this is wasted when counting whole cents. - Support for very large numbers at the expense of precision is actively bad, as the precision must always be down to individual cents. So the useful range of floats is much reduced when using floats for counting, approx 54 bits out of a 64 bit float are used. Instead ints (“counting numbers”) are much better for counting cents than floats (which approximate the continuous real numbers in a finite number of bits).
- ChrisLomont 8y agoYes, I have. I also have a math PhD, have written scads of scientific and numerical software, and have written articles on floating-point math. So now that we have enough of our personal accolades out of the way, let's focus on facts regarding calculations: How did you use ints to compute compounded interest on loans? I asked that above, and you avoided it. I ask again. For example, suppose you have a mortgage where you lent $100K at 5% annual, compounded 12 times a year, for 30 years, and you need basic values regarding this loan. Often in such calculations you need to compute 100K*(1+0.05/12)^360. How do you do that with integers? Naively you need (1+(1/20)/12)^360, which as a reduced fraction each of the numerator and denominator have over 2800 binary digits. Do you really do this with integers? Now put that in a mortgage trading or pricing system where it needs to do millions/billions of those per second. Doing this as double gives enough precision to make the difference between computed and infinitely precise negligible (approx. 10^-17 error). It's easy to make examples where doing incremental calculations, rounding to pennies and storing, results in long term error. In these cases I don't see how do to it with integers without massive overhead. And this is a trivial, common example. Doing stuff like hedge fund stuff, or anything using numerical integration to make models for pricing, would be astounding hardly to do with integer only math. What finance software did you write? A simple ledger works fine as integers. Anything more complex will hit performance and scaling issues soon after the basics.