thanks all!
On Jan 18, 2008 3:49 PM, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Fri, 18 Jan 2008 13:55:17 +0800, "J. Peng" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > why this happened on my python? > > > > >>> a=3.9 > > >>> a > > 3.8999999999999999 > > > > I wanted 3.9 but got 3.89................ > > How to avoid it? thanks. > > > Avoid it? You don't... You alleviate the concern by understanding > that floating point is only precise if the value is a fraction of 2: 1, > 0.5, 0.25, 0.125... > > Computer Science recommends that one does NOT compare two floats for > equality -- instead one should compare the absolute value of the > difference of the two floats against some required epsilon (ie, how far > apart two floats can be and still be considered equal... > abs(f1 - f2) < 0.000001 > for example) > -- > Wulfraed Dennis Lee Bieber KD6MOG > [EMAIL PROTECTED] [EMAIL PROTECTED] > HTTP://wlfraed.home.netcom.com/ > (Bestiaria Support Staff: [EMAIL PROTECTED]) > HTTP://www.bestiaria.com/ > > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list