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

James J. Besemer jb at cascade-sys.com
Tue Oct 1 18:29:10 EDT 2002


Paul Rubin wrote:

>"James J. Besemer" <jb at cascade-sys.com> writes:
>  
>
>>>>>>(.70 * .05) + .000000001
>>>>>>
>>>>>>            
>>>>>>
>>>rounds to the right thing.
>>>
>>>      
>>>
>>Nope.  It helps in some cases but introduces errors in other cases
>>(e.g., negative numbers).
>>    
>>
>
>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.

Regards

--jb

-- 
James J. Besemer		503-280-0838 voice
2727 NE Skidmore St.		503-280-0375 fax
Portland, Oregon 97211-6557	mailto:jb at cascade-sys.com
				http://cascade-sys.com	








More information about the Python-list mailing list