3 ms·
15 by default is reasonable for everyday programming; we don't need results like 0.30000....4 popping up in our faces. That just changes the problem. Yo
by jordigh 11y ago
15 by default is reasonable for everyday programming;
we don't need results like 0.30000....4 popping up in
our faces.
That just changes the problem. You can't get rid of rounding error by representing decimal numbers in binary. 0.3 - 0.2 - 0.1 still won't show up as zero even if you only display 15 decimal digits.
- kazinator 11y agoI'm not about to change the floating-point type to a non-binary support. I think that 15 digits is the "right" value for ordinary display purposes. If you present a literal value of up to 15 digits to the machine, it gets converted to some approximation which, when printed back with 15 digits of precision, gives you the same digits. By using 15 we avoid this: 1> (let ((*flo-print-precision* flo-max-dig)) (tostring 0.3)) "0.29999999999999999" 2> (tostring 0.3) "0.3" I have no "rounding error" because I haven't performed a calculation. I understand that when I enter 0.3 into the machine, the floating-point value isn't exactly 0.3. I have an error, because the representation can only provide a close approximation of 0.3. Yet I know that this approximation is so close to 0.3 that I would like it printed that way. Now of course it will be printed that way if I round to, say, four places. But that will throw away precision for other numbers. If I round to DBL_DIG digits (15), I get the maximum precision, without having my input numbers altered into something else. It is useful and elegant for the default printing precision to be as high as possible, yet such that numbers that I enter into a REPL are echoed back at me pretty as I entered them, modulo choice of notation. No, of course, DBL_DIG doesn't guarantee that I can do any sequence of calculations, like 0.3 - 0.2 - 0.1 and still get back a result which is exact to DBL_DIG digits! There is no lower bound on how inaccurate a floating-point calculation can be, if it is carried through enough iterations!