4 ms·
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
by moonchild 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. 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.)
- lmm 3y ago> 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. Adding 0.1 and 0.2 to get 0.3 is hardly advanced mathematics. > Otherwise, the results will appear to manifest as just some inaccuracy incurred after every operation, just the same as with binary floating point. Perhaps, but it will be a comprehensible inaccuracy. Running out of decimal places is a well-known and understood phenomenon, and something already experienced with regular calculators.
- heisenbit 3y agoFor better or worse Java is one of the major languages in the financial sector.
- pasc1878 3y agoTrue but it does have the BigDecimal class which is what you should use for money, unless you are using derivatives pricing when thr person writing the code must understand floating point.
- drekipus 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. "float" is usually the second thing taught in the math tutorial, right after "int", in many languages. JavaScript and many other languages hide many things away and just call everything "a number" which is a float by disguise. "Decimal" types are usually hidden in some standard library, and not as a first class primitive type of the language. Stop victim blaming, that's not going to get the discussion anywhere. You HAVE to acknowledge that the first option is non-obvious of its flaws.
- deleted 3y ago[deleted]