7 ms·
I once inherited the development and maintenance responsibilities on a financial forecasting/business development app. There were lots of expected value computa
by alexjplant 4y ago
I once inherited the development and maintenance responsibilities on a financial forecasting/business development app. There were lots of expected value computations in the form of adding up potential revenues multiplied by their probability of win with costs subtracted (i.e. currency values). The previous developer had used floats everywhere resulting in runoff values as seen here.
I started using decimal in all of the new features in an effort to mitigate this but it resulted in even more headache as I now had a bunch of casts floating around on top of the truncation band-aids that I had to implement for existing lengthier calculations. My plan was to refactor the whole app and SQL schema but if memory serves I got pulled onto something more pressing before I had the chance.
This was especially disappointing to me because this was all implemented in C# and T-SQL which are languages with first-class support for decimal numbers. It wouldn't surprise me if the app is still in use today with some hapless dev halfway across the country whacking these bugs as they pop up.
- parhamn 4y agoThis makes me wonder why Decimals aren’t part of std libs in Javascript or Golang.
- lifthrasiir 4y agoIt is hard to design. There should be some sort of precision and rounding mode control throughout calculation, meaning there should be some sort of implicit state or those controls should be sprayed into every operation. The latter is explicit but tedious [1]. The former will still surprise people from time to time. IEEE 754 binary number is sort of working well in this aspect. [1] See QuickJS's BigDecimal extension for example: https://bellard.org/quickjs/jsbignum.html#Properties-of-the-BigDecimal-object https://bellard.org/quickjs/jsbignum.html#Properties-of-the-...
- ClumsyPilot 4y agothat's eactly why it needs to be in standard library- so people dont make mistakes reinventing the wheel
- lifthrasiir 4y agoOnly if you have a proven design. I don't think we have any satisfactory design at all.
- ClumsyPilot 4y agoWhat's wrong with https://en.m.wikipedia.org/wiki/Decimal64_floating-point_format https://en.m.wikipedia.org/wiki/Decimal64_floating-point_for... Or with C# 128 bit implementation of decimal? Is there no good implementation anywhere?