Decimal arithmatic, was Re: Python GUI app to impress the boss?

Paul Rubin phr-n2002b at NOSPAMnightsong.com
Tue Oct 1 19:17:00 EDT 2002


"James J. Besemer" <jb at cascade-sys.com> writes:
> >OK, fix the rounding direction:
> >
> >    def round(x):
> >      if x < 0: sign = -1.0
> >      else: sign = 1.0
> >      return sign * (abs(x) + .00000001)
> >
> I believe this still contains a hidden error.  I believe in all cases
> that blindly adding a fudge factor fixes some cases and makes others
> worse..  But I don't have time to prove it.  If you don't believe me
> then feel free to use the above definition.  It'll pro'lly be right
> most of the time.

I haven't yet seen a complete definition of "right", so I have no way
to prove or disprove that the rounding function above always gives the
"right" answer.



More information about the Python-list mailing list