5 ms·
> In my perfect world floats don’t have inf, nan and base-2 exponent I'm quite unsure what do you want as floats then?
by temac 3y ago
> In my perfect world floats don’t have inf, nan and base-2 exponent
I'm quite unsure what do you want as floats then?
- Symmetry 3y agoDecimal floating point is a standard that some people use and which even has hardware support in some IBM cores. https://en.wikipedia.org/wiki/Decimal_floating_point https://en.wikipedia.org/wiki/Decimal_floating_point
- eru 3y agoYou can do that, but I think for most applications where you want decimal, you can get away with fixed point computation? Eg if you want to calculate with money, just specify everything in terms of cents (or 0.001 of a cent or whatever), and then use an integer data type. Perhaps even an unlimited size integer data type.
- afiori 3y agoI feel like at some point the performance hit of using actual rationals (pairs of bignums) makes sense
- adgjlsfhk1 3y agoThe downside of rationals is that they degrade extremely quickly as soon as you take a sqrt or do trig. Decimal floating point has the advantage of losing accuracy in the places people are used to.
- afiori 3y agoI believe that for almost all rationals trig functions never return a rational so you must have some kind of rounding tecnique. An advantage of rationals is that you have much more freedom in handling how the rounding works, for example you can limit your rounding to produce fractions n/2^m and then they behave sort of like floats or n/10^m and then they behave like decimals while still being able to know that basic arithmetic operations (+, *, -, /, <, <=, <>, mod, exponentiation by integer) work as precisely as you want them to. GPUs, ML, an massive numericall processing will want to always use floats, ints, posits[0] with operations that can be efficiently implemented in hardware but most apps could easily afford to use bigint/bigint rationals for most things. [0] https://spectrum.ieee.org/floating-point-numbers-posits-processor https://spectrum.ieee.org/floating-point-numbers-posits-proc...
- wruza 3y agoAnd don't forget to adjust after multiplication, e.g. ($ * kg) = (price * qty) / (10 ^ qty_scale). But not before you finished with a "sequence-point" in calculations, cause otherwise rounding will accumulate, e.g. ((price * qty) * (100 * (10 ^ pct_scale) - discount)) / (10 ^ (qty_scale + pct_scale)). Thus no operator[+-*/%^] magic for you either. Also, all these temporary ...0000000s will bite into your "mantissa" part along the way. Fixed point sounds reasonable until you have to actually implement a sales/debt/tax/trade-related routine that takes a couple of pages with proper decimals alone.
- marcosdumay 3y agoIt's quite clearly decimal floats, with instant trapping instead of bad values. IMO, with the sheer amount of silicon modern processors use for incredibly specialized gains, there's no reason our computers should be specialized for scientific computations when they could support daily computations too. You obviously do not want decimals on your GPU, but the choice on the CPU is out of wack.
- grotorea 3y agoDo we need support or is just doing it on the CPU without specialized instructions fast enough?
- marcosdumay 3y agoGood question. Today we are incredibly biased into base-2, using it many times where we should be using base-10 instead. So the performance of our current software is not a good example. But maybe we can get a good example if we just divide our current numbers by instruction types and multiply the FP time by ~100. I have seen many studies that measure how much time software spends on FP instruction. But unfortunately, we live in a web search dark age, so I don't have references. I remember that FP-heavy code spends 10% to 20% of the time on those, what means that emulation will increase your execution time up to something on the 10x - 20x range. That's perfectly fine for a lot of applications, but does limit several niches. But as far as I know, the question of how FP-heavy is the FP-heavy software that does daily calculation is unanswered.
- eru 3y agoWhat kinds of applications do you have in mind that are (a) CPU bound (or GPU bound), and (b) would benefit from your 'saner' numbers? Eg graphics in general or video decoding specifically is definitely something that does a lot of processing; but I don't see how it would benefit from eg base-10 numbers? Spreadsheets might benefit from base-10 numbers by default; but they are not CPU bound at all. Mostly they just sit around and wait for user input.