Re:0.30000000000000004
by smitherfield on Sunday April 02, 2017 @04:31PM
(#14018894)
My personal view is decimal arithmetic should be the default and floating-point should be the library in scripting languages. And probably also Java/C#/Go-type languages.
[ Parent
| on HN ]
Re:0.30000000000000004
by richdougherty on Sunday April 02, 2017 @04:58PM
(#14019009)
My personal view is that the programmer needs to know the difference because there are important tradeoffs to consider.
I do however think it should be easier to use decimal arithmetic. I've written financial apps in both Java and JavaScript and I wish both languages had native syntax and support for decimal numbers and arithmetic. JavaScript has nothing built-in and Java's BigDecimal class is clunky to use.
Re:0.30000000000000004
by adrianratnapala on Sunday April 02, 2017 @06:09PM
(#14019329)
Decimal only takes care of a subset of cases. I.e. those where the source data nicely lines up in decimal. Good for finance (although I think Britain made a mistake when it gave up the old penny and the shilling). But even there, you sometimes have to divide by numbers like 12 and 365.
The point is NO representation is going to be idiot proof. So you just need to make a sufficient set of representations easy to use, and then try to teach the "idiots" what the underling issues are.
Decimal does only take care of a subset of cases, true. But 1) it's a very common subset, and 2) when it breaks down, people generally understand how and why, because they've dealt with it elsewhere.
Why? Is decimal faster than arbitrary precision? If not, arbitrary precision should probably be the default (or binary).