Math errors in python
Anna Martelli Ravenscroft
anna at aleax.it
Sun Sep 26 14:17:46 CEST 2004
Note: I posted a response yesterday, but it apparently never appeared (I
was having some trouble with my newsreader) so I'm posting this now. My
apologies if it is a duplicate.
Alex Martelli wrote:
> Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:
> ...
>
>>The issue here is that Python's behavior confuses the hell out of some
>>new users. There is a separate area of confusion, that
>>
>> a = 2 / 3
>>
>>sets a to 0, and to clear that up, the // operator was introduced and
>>Python 3.0 will supposedly treat / as floating-point division even
>>when both operands are integers. That doesn't solve the also very
>>common confusion that (1.0/3.0)*3.0 = 0.99999999. Rational arithmetic
>>can solve that.
>
>
> Yes, but applying rational arithmetic by default might slow some
> computations far too much for beginners' liking! My favourite for
> Python 3.0 would be to have decimals by default, with special notations
> to request floats and rationals (say '1/3r' for a rational, '1/3f' for a
> float, '1/3' or '1/3d' for a decimal with some default parameters such
> as number of digits). This is because my guess is that most naive users
> would _expect_ decimals by default...
I agree. Naive (eg, non-CS, non-Mathemetician/Engineer) users who grew
up with calculators and standard math courses in school may have never
even heard of floats! (I made it as far as Calculus 2 in college, but
still had never heard of them.)
This brings me to another issue. Often c.l.py folks seem surprised that
people don't RTFM about floats before they ask about why their math
calculations aren't working. Most of the folks asking have no idea they
are *doing* float arithmetic, so when they try to google for the answer,
or look in the docs for the answer, and skip right past the "Float
Arithmetic" section of the FAQ and the Tutorial, it's because they're
not DOING float arithmetic - that they know of... So, of course they
won't read those sections to look for their answer, any more than they'd
read the Complex Number calculations section... People who know about
floats con't need that section - the ones who do need it, con't know
they need it.
If you want people to find those sections when they are looking for
answers to why their math calculations aren't working - I suggest you
remove the "FLOAT" from the title. Something in the FAQ like: "Why are
my math calculations giving weird or unexpected results?" would attract
a lot more of the people you WANT to read it. Once you've roped them in,
*then* you can explain to them about floats...
Anna Martelli Ravenscroft
More information about the Python-list
mailing list