good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
It is not a bug that Perl rounds the display of numeric values to a number of digits that is fewer than the number of digits of precision that the internal floating point format achieves
It depends upon how you measure that "number of digits". Sure - if you allow more than 15 decimal digits then you lose the guarantee that different strings will assign different values. (It's possible that 2 different 16-digit strings will assign to the same value.) But there are a vast number of values that cannot be assigned if you restrict yourself to 15 decimal digits. To be able to assign each and every value you need 17 decimal digits, minimum. To me the sane thing is to have print() deliver a value that, when assigned back to a scalar, will result in the same value. I think the following is rather pathetic: Why do we have to put up with that sort of anomaly when it could be eradicated by simply providing just *2* more digits of precision ? Is 17 decimal digits really that much more unreadable than 15 digits ? you get even more complaints when a computation should yield 1/100 but the result gets displayed as "0.01000000000000002" I don't think that's the right example. For me, I have to request 18 decimal digits of precision to get the trailing "2", and being surprised by that sort of result when more than 17 digits have been requested is a "user bug". The "correct" precision is 17 decimal digits - not 18. A better example is: This happens because 0.10000000000000001 and 0.1 have the same internal floating point representation, and that representation is closer to 0.10000000000000001 than 0.1. I actually don't have any problem with that - but if we want to avoid such surprising results, there's a more refined way of dealing with this type of issue than simply getting the chainsaw out and hacking the tail off everything. I am told that python, for example, utilises this refinement. That is, python prints out 17 decimal digits but still prints 0.1 out as '0.1'. Update: Current bug report regarding this issue is here Cheers, Rob In reply to Re^3: Variables are automatically rounded off in perl (humans)
by syphilis
|
|