simple float numbers problem

Ben Finney bignose-hates-spam at and-benfinney-does-too.id.au
Sun Nov 9 06:18:34 EST 2003


On Sun, 09 Nov 2003 00:10:14 -0800, Tim Roberts wrote:
> Another solution is to use a "CloseTo" function to do the comparison:
> 
>   def CloseTo(x,y):
>       return abs(x-y) < 0.005

A modified CloseTo() that allows a varying epsilon:

    def CloseTo( x, y, epsilon=0.005 ):
        return ( abs( x - y ) < epsilon )

-- 
 \       "During the Middle Ages, probably one of the biggest mistakes |
  `\   was not putting on your armor because you were 'just going down |
_o__)                                 to the corner.'"  -- Jack Handey |
Ben Finney <http://bignose.squidly.org/>




More information about the Python-list mailing list