off topic but please forgive me me and answer

Patrick Maupin pmaupin at gmail.com
Thu Apr 1 22:58:31 EDT 2010


On Apr 1, 9:50 pm, Lie Ryan <lie.1... at gmail.com> wrote:
> On 04/02/10 13:01, Patrick Maupin wrote:
>
>
>
> > On Apr 1, 7:49 pm, Tim Chase <python.l... at tim.thechases.com> wrote:
> >> David Robinow wrote:
> >>> $ python -c "print 1/2 * 1/2"
> >>> 0
>
> >>>  But that's not what I learned in grade school.
> >>> (Maybe I should upgrade to 3.1?)
>
> >> That's because you need to promote one of them to a float so you
> >> get a floating-point result:
>
> >>    >>> 1/2 * 1/2
> >>    0
> >>    >>> 1/2 * 1/2.0
> >>    0.0
>
> >> Oh...wait ;-)
>
> >> -tkc
>
> > Hmmm, I think I'm starting to see why we need math.fsum() to take care
> > of those rounding errors...
>
> hmm?
>
> >>> import math
> >>> math.fsum([1/2, 1/2])
>
> 0.0
>
> it doesn't appear to take care of those rounding errors, not in this
> case at least.

you're right!  I mis-read the problem.  What we REALLY need is a good
math.fmul()   ;-)



More information about the Python-list mailing list