PEP proposal for round(x,n) enhancement
markus at schabi.de
Thu Sep 13 00:27:04 CEST 2001
Christopher Smith <csmith at blakeschool.org> schrub:
> Markus writes:
>>The problem is that you can't store this information in a floating
>>point number. I just tried the following:
>>This, I give the number with 1 significant digit, and end up having
>>displayed 17 "significant" digits.
> Yes and no. You told Python to show you in decimal format how '0.2'
> represented as a binary number. If you had said "print 0.2" you would
> obtained 0.2 and if you had said "print 0.2000" you would have
> obtained the same
> thing (even though you wanted 4 significant digits).
And this is what I meant - the float doesn't store how many digits are
significant, so when you round to n digits, you often get an
approximation to the rounded number, and this way don't have any
information about the accuracy afterwards.
>>So you may only round (or whatever we call it) to powers of two, but
>>not to powers of 10 (digits) without having rationals or decimals.
> Yes, you are right in that there is no way to exactly represent some
> exactly as floating point numbers but this has nothing to do with
> rounding a
> number (to the closest approximation that you can) to a specific
> digit. This is
> the task of the round() function. My proposal only has to do with
> enhancing the
> syntax used by the round() function.
And enhancing the semantics :-)
"The strength of the Constitution lies entirely in the determination of
each citizen to defend it. Only if every single citizen feels duty
bound to do his share in this defense are the constitutional rights
secure." -- Albert Einstein
More information about the Python-list