4 ms·
For general purpose computing (approximating real quantities) floats with base-2 exponents are just right on base-2 computers. For dealing with money (and other
by FabHK 3y ago
For general purpose computing (approximating real quantities) floats with base-2 exponents are just right on base-2 computers. For dealing with money (and other quantities that are fundamentally integer), they might be the wrong choice, but that's well understood and sort of obvious (use integers to handle integers).
- PaulHoule 3y agoI disagree. There are many non-professional programmers who get baffled by various "computerisms" such as 0.1 + 0.2 != 0.3 Excel tries to hide this but ends up doing even stranger things if you push it hard enough. I think a lot of people who could use computers to put their skills on wheels just give up because of this "lack of empathy" that manifests here and in other places. If you do 0.1 + 0.2 - 0.3 on a pocket calculator you get the right answer and you should get the same right answer in a Jupyter notebook. The only person who should be exposed to the base 2 arithmetic of the computer is a professional programmer who knows assembly language. There are numerous social consequences of this that are harmful such as the perception that computer programmers are "grinds" and "nerds" and the idea that "idea people" are more worthy than the people that execute, etc.
- kragen 3y agooh, i thought you meant base 2 as opposed to base 16 (like the 360) there is a significant performance penalty for bcd arithmetic, so bcd floating point has never been attractive to the customers for floating point: cray buyers, fortran programmers, gamers, analog circuit designers, climatologists those people don't really care about the beginner issues you mention if you're willing to accept a performance penalty in exchange for easier learning, you can implement decimal arithmetic in software; many people have, and it's in the cobol and sql standards and the python standard library. the version i implemented in bubbleos is 83 lines of c, https://gitlab.com/kragen/bubbleos/blob/master/yeso/decimal.h https://gitlab.com/kragen/bubbleos/blob/master/yeso/decimal.... https://gitlab.com/kragen/bubbleos/blob/master/yeso/decimal.c https://gitlab.com/kragen/bubbleos/blob/master/yeso/decimal.... and compiles to about 1.3k of code but a lot of us are using cpython in jupyter to prototype algorithms we want to run as fast as possible, so we want it to behave like the floating-point hardware does
- lifthrasiir 3y agoYou are entirely right that user-facing programs should strive to hide IEEE 754 artifacts (see, for example, the Android calculator app that uses exact real arithmetic). But if you are programming, there are tons of quote-unquote computerisms that we have for a good reason but are not really intuitive for newcomers. The whole concept of variables, pointers and general indirections, zero-based indexing, (pseudo)randomness, Unicode, time complexity, concurrency and parallelism and so on. Many (but not all, I admit) professional programmers take them as granted but they are just as arcane as the concept of base-2 floating points.
- moonchild 3y agoIf somebody does not understand the implications of a computation such as a floating-point 0.1 + 0.2, they should not be using floating-point. It's not the job of the language to protect them from that. Decimal floating-point will be prone to very similar malfeasances, if that is what you are proposing; somebody unaware of the issues of binary floating point will not be helped by decimal floating point. I do think it would be a good idea for programming languages to expose more exact number representations (for example, rational numbers, which are supported by some programming languages). But numbers are complicated, and you will never be able to imbue a computer with a number type that always behaves exactly the way that someone who knows nothing of computers would naively expect. Even mathematica does not quite manage it, and mathematica takes some somewhat extreme measures which would not be considered acceptable in many other general-purpose languages.
- lmm 3y ago> If somebody does not understand the implications of a computation such as a floating-point 0.1 + 0.2, they should not be using floating-point. It's not the job of the language to protect them from that. Then what is the job of the language? Programming languages should nudge their users in the right direction; they should be safe and maintainable by default. Sometimes sharp-edged parts are necessary (e.g. for performance) and they should be made available to those who need them, but they shouldn't be front and center. E.g. floating point literals should be a high/arbitrary precision decimal type by default, similar to what Python does with integer literals. > Decimal floating-point will be prone to very similar malfeasances, if that is what you are proposing; somebody unaware of the issues of binary floating point will not be helped by decimal floating point. Disagree. Decimal calculations getting rounded off is a problem that is a lot easier to see and understand.
- moonchild 3y ago> Decimal calculations getting rounded off is a problem that is a lot easier to see and understand. If you carefully, tediously work by hand some calculations such as addition, multiplication, or division (but not, say, square roots, exponentials, or sines, since there are no generally known methods for computing those by hand), you may be able to replicate some specific results of the computer without needing to learn anything new. I don't really see what the point of doing that would be. Oh, and you must use banker's rounding, which is also not generally done. Otherwise, the results will appear to manifest as just some inaccuracy incurred after every operation, just the same as with binary floating point. The full complexity of error analysis remains. (Note also in particular that addition, multiplication, and division are closed over the rationals, which can be readily represented exactly by computer—I did mention I think rationals are a good thing.)
- quickthrower2 3y agoOne option is to convert the world to base 16 arithmetic instead of 10.
- eternityforest 3y agoI just think of floats as fuzzy analog values. The only precise operation you can do is copying. Everything else, you assume it's noisy. It's not real analog noise, but reasoning about rounding is hard if you're not good at math, it's something you can explain easily, and it prevents you from doing clever stuff that will confuse the next person. It's the opposite of being an idea person. I just accept them as a practical approximation, not a tool for doing real math, and move on. If you come from electronics it makes perfect sense. Voltages are pretty much always noisy even if it's picovolts. If I need precision I use ints or dedicated libraries.
- constantcrying 3y agoThat isn't a computerism. It is a feature of floating point arithmetic. Computers are perfectly able to calculate perfectly. >should get the same right answer in a Jupyter notebook. The only person who should be exposed to the base 2 "Why does my notebook take hours to do a simple task" >There are numerous social consequences of this that are harmful such as the perception that computer programmers are "grinds" and "nerds" and the idea that "idea people" are more worthy than the people that execute, etc. The benfits of floating point arithmetic easily outweigh people having to learn it.
- wruza 3y ago"Why does my notebook take hours to do a simple task" “Because the chip it is running on doesn’t have native base-10 math”? See also “why my notebook [is fast but] yields incorrect results”. The benfits of floating point arithmetic easily outweigh people having to learn it. GP talks about saving non-low-level programmers from base 2 FP, not about removing it. CPUs could use an additional block (or mode) of base 10 exponent FP. This and other geeky issues make programmers programmers instead of making everyone a programmer. The consequence of this is much heavier than any benefits of base 2 FP.
- constantcrying 3y ago>“Because the chip it is running on doesn’t have native base-10 math”? Base 10 fixes exactly zero of the problems with floating point. Decimal floating point exists as a standard already. It is even part of the upcomming C standard. But again decimal arithmetic is just as weird as floating point arithmetic. The change of base s irrelevant, except for a few niche applications. >The consequence of this is much heavier than any benefits of base 2 FP. Totally false. Decimals don't fix floats. They are just as weird. Changing the base is irrelevant to the inherent properties of floats and using base 10 instead of base 2 just means that with a very high chance you get something even worse. If you do not understand the basics of floating point arithmetic you should not be programming software. Tough world out there for people who refuse to learn, I know.
- 3y ago