On Thu, Jan 12, 2017 at 11:50 PM, Stephan Houben <stephan...@gmail.com> wrote: > 2017-01-12 13:17 GMT+01:00 Chris Angelico <ros...@gmail.com>: >> >> Most of the time one of my students talks to me about decimal vs >> binary, they're thinking that a decimal literal (or converting the >> default non-integer literal to be decimal) is a panacea to the "0.1 + >> 0.2 != 0.3" problem. > > > Indeed. Decimal also doesn't solve the > 1/3 > issue. > > I don't understand why people always talk about Decimal, > if you want math to work "right" you probably want fractions. > > (With the understanding that this is for still limited value of "right".)
My usual go-to response is that if you want perfect arithmetic with no rounding errors, your *ONLY* option is symbolic math, where sqrt(8) returns 2√2. It's pretty obvious that this gets unwieldy really fast, and rounding errors are a fact of life :) Rationals have their own problems (eg it's nearly impossible to eyeball them for size once they get big), and still don't solve everything else. >> Perhaps the real solution is a written-up >> explanation of why binary floating point is actually a good thing, and >> not just a backward-compatibility requirement? > > > I have sometimes considered writing up "Why the aliens of Epsilon Eridani, > whose computers use 13-valued logic, still use floating point numbers > with base 2." > > (Short overview: analysis form first principles shows that the base should > be: > 1. an integral number > 1 and > 2. as small as possible (to minmax the relative rounding error)) > > The list of candidate bases satisfying these criteria is: 2. > That's exactly the sort of thing I'm talking about. Among other things, only binary floating point guarantees that x <= (x+y)/2 <= y for any x <= y. (At least, I think only binary - I know decimal can't ensure that, and I haven't tested everything in between.) You're way more an expert on this than I am - my skill consists of reading what other people have written and echoing it to people :) ChrisA _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/