7 ms·
DEC64: Decimal Floating Point
- jensenbox 11y agoPersonally, I like this a lot. What are the potential downsides?
- Others 11y agoI think that the chance of this becoming prevalent is low. While it has its merit as a representation, floating point is already "good enough" for most computations. More importantly, it is ubiquitous. Additionally, I don't know if there are enough compelling problems that require decimal numbers, can't take the hit of software emulation, and are willing to bind their performance to hardware that would take a while to be adopted, if at all. I could be wrong though.
- iopq 11y agoFloating point is really stupid for most computations. Can't store floating point numbers when dealing with money (have to store the number of cents or something equally stupid so you don't tell Paypal to sell something for $12.999999999999996 because they won't accept that price) Can't store floating point numbers when you really need a ratio because it won't even work after you round it unless you reconcile different settings for precision. Decimal won't help here either. So outside of niche scientific uses or something like graphics where you need performance, what do you really need floating point numbers for? I haven't had a need for floating point numbers outside of some mathematical formulae.
- theseoafs 11y ago> So outside of niche scientific uses or something like graphics where you need performance, what do you really need floating point numbers for? I haven't had a need for floating point numbers outside of some mathematical formulae. This is... a weird thing to say. Obviously floats are going to be most useful for math, and not useful for much else. They're number types.
- iopq 11y agoYes, but decimal numbers would be useful in: 1. Game score display where fractional points are possible 2. Currency 3. Any amount displayed to humans (like pounds of beef sold) because decimal number correspond to what you're going to display to the user, while binary numbers are only useful for the result they produce inside an algorithm
- theseoafs 11y agoSo what is your point?
- otabdeveloper 11y ago> what do you really need floating point numbers for? For representing real (i.e., potentially irrational or transcendental) numbers. Irrational and transcendental numbers are actually very common in nature. But you're right that representing rational numbers with floating point is stupid. Instead of inventing new one-size-fits-all coding schemes, people should focus instead on making the idea of a rational number type mainstream. This wouldn't even be an issue worth discussing if popular programming languages and DBMS's supported rational numbers.
- deleted 11y ago[deleted]
- chillingeffect 11y agoI like it, too. The word size is so large it's not a goo. Dimple dance match for embedded processing. Let's try that again: "not a good impedance match"
- anamexis 11y agoThere have been some pretty heavy critiques of it when it has been posted to HN in the past, e.g. https://news.ycombinator.com/item?id=7367021 https://news.ycombinator.com/item?id=7367021
- rcthompson 11y agoIt looks like the biggest critique is that checking for equality is slow, but checking floats for equality is almost always a bug anyway.
- jhallenworld 11y agoThe base is 10, but the mantissa is in binary. Before you add or subtract you must get the numbers to have equal exponents. In other formats you can do it with shifting, but this format requires binary multiplication or division.
- nils-m-holm 11y agoS9fES (http://t3x.org/s9fes/ http://t3x.org/s9fes/) uses decimal-based real numbers and does multiplication, division and exponent equalization by shifting. It's not hard, since one digit equals one byte.
- cbd1984 11y agoIt'll never replace the VAX.
- deleted 11y ago[deleted]
- MichaelGG 11y agoWhy would you ever use floating point for money? You're just asking for rounding errors if you actually use the range, aren't you?
- protomyth 11y agoUsing floating point for quantities of commodities is an equally bad idea. Conversations and rounding will kill you.
- wtallis 11y agoHas any economic calculation or accounting ever actually had 16 significant digits? If you're talking about $360 trillion, you can only pretend to have a quantity that's correct to the last cent; even if you used sufficient precision for the calculations, your number cannot be connected to the real world with that much precision.
- detaro 11y agoLess valuable currencies have bigger numbers (eg 1 USD = 17472.5 BYR), so suddenly it's only a few million USD worth of money. Even worse for extreme examples of inflation. Not that the individual unit is actually worth anything there, but calculating it with enough precision is probably easier than the regulation to deal with where money is allowed to disappear or to suddenly exist.
- wtallis 11y agoLess valuable currencies produce bigger numbers, but they don't yield more precise specification of value. Even though it is severely inflated, the smallest active denomination of BYR is only a little smaller than a US cent, and any real-world scenario involving large quantities (larger than the entire supply of BYR!) will easily tolerate rounding to that precision.
- detaro 11y agoYeah, the real world value is not very high, but I would be surprised if you officially could accept errors larger than the smallest unit and wouldn't get potentially into trouble when something adds up wrong.
- rcthompson 11y ago> nan is equal to itself. Why?
- deleted 11y ago[deleted]
- kazinator 11y agoBecause the designer is sane, and understands that A is A, no matter what A is: https://en.wikipedia.org/wiki/Law_of_identity https://en.wikipedia.org/wiki/Law_of_identity
- the_mitsuhiko 11y agoIt sounds more like the designer does not understand what NaN is. The whole point of NaN is that it propagates through all operations so making (Nan == Nan) == true defeats that purpose.
- ino 11y agoThe designer is Douglas Crockford, I doubt he doesn't understand NaN.
- kazinator 11y ago> It sounds more like the designer does not understand what NaN is. The whole point of NaN is that it propagates through all operations so making (Nan == Nan) == true defeats that purpose. In that case, making (NaN == NaN) == false also defeats it. false isn't NaN either. If true or false propagates out of a function whose inputs are NaN, NaN has failed to propagate.
- joesb 11y ago> In that case, making (NaN == NaN) == false also defeats it. false isn't NaN either. With that logic, you could say making (1 == 1) == true is wrong, because 1 isn't true. > If true or false propagates out of a function whose inputs are NaN, NaN has failed to propagate. He meant Nan propagates through calculation operation, not comparison operation. As in, result of calculating Nan + 1 is NaN. So if you have "A = NaN" and "B = A + 1", you have the situation that both A and B is NaN but A does not equal B.
- deleted 11y ago[deleted]
- JesperRavn 11y agoI don't know if the popularity of this on HN is a case of the emperors new clothes, or if I am really missing something, but to me this is sophomoric. There is nothing inherently base-10 to finance or any other field. Finance deals in exact quantities but that is because it deals in exact units. E.g. if a single stock tick is 0.1 cents, then a 0.11 cent increase is as meaningless as a 1/30 cent increase. There is no more need to represent arbitrary exact decimals as there is to represent arbitrary exact binary decimals. All that finance needs is integer multiples of the relevant unit. And presumably this is already hardcoded into their COBOL or FORTRAN code. Nothing presented on that page made me thing that DEC64 would be useful for anything that integer arithmetic in the right units would not be better suited to.
- ArchD 11y agoYou may not know beforehand that the smallest unit is $0.01. What if it becomes $0.001 or $0.0001 later? You'll have to migrate your data to use the new smallest unit. If you use decimal floating point, you don't need to deal with that.
- tomsmeding 11y agoTotally agree! If you want to calculate with cents, or tenths of cents for that matter, just use an integer based on that unit. You have not just 56, but 64 bits of precision, and no loss of generality in the money field.
- detaro 11y agoAnd then you get a conversion rate with 1/1000 of a cent, and you have to manually make sure your fixed point gets converted correctly. Or worse, you get a conversion rate input with a variable number of digits after the decimal point, and you have to use all of them. For simpler cases this is fine, but for more complex ones I suspect the mental overhead for developers would get problematic.
- pgaddict 11y agoExactly. Then you realize you need to deal with values with different scales, because "amount of money" may need 2 decimal places while "exchange rate" may need 3, so you start tracking scales. At which point you've just reinvented basically the same data type as described here.
- jhallenworld 11y agoI wrote an arbitrary precision ASCII decimal floating point library. No conversion required at all! https://github.com/jhallen/joes-sandbox/tree/master/lib/farb https://github.com/jhallen/joes-sandbox/tree/master/lib/farb (There are much faster alternatives, this was just for the fun of it).
- legulere 11y agoI find it funny how the author easily dismisses IEEE decimal floating point because it hasn't seen huge adaptation since 2008 when it was released. It since has been implemented in some CPUs: IBM z9 upwards, POWER 6 upwards
- pgaddict 11y agoYeah, exactly the same impression here. And it's not the case that there are no other software implementations - for example GCC supports _Decimal32/64/128 since 4.3 (https://gcc.gnu.org/onlinedocs/gccint/Decimal-float-library-routines.html https://gcc.gnu.org/onlinedocs/gccint/Decimal-float-library-...).
- pepijndevos 11y agoLast time this was on HN, people also wondered why you'd have hundreds of representations of the same number, and how you'd do a fast equality check.
- ino 11y agoI like this idea for in the sense it makes life easier, like garbage collection for example. It's good to understand what's going on behind the scenes, how memory is allocated and managed, and the floating point quirks and their binary nature, but for many general applications It'd be nice to have peace of mind that (0.1 + 0.2 == 0.3) returns true.