Re: Precision for equality of two floats?

2005-11-29 Thread Dan Sommers
On Tue, 29 Nov 2005 14:31:46 GMT, [EMAIL PROTECTED] (Bengt Richter) wrote: > On Mon, 28 Nov 2005 07:58:37 -0800, [EMAIL PROTECTED] (Alex Martelli) wrote: >> Python's builtin floats compare for exact bit-by-bit equality -- no >> "threshold". You may want to look at the allclose function in the >

Re: Precision for equality of two floats?

2005-11-29 Thread gene tani
Anton81 wrote: > Hi! > > When I do simple calculation with float values, they are rarely exactly > equal even if they should be. What is the threshold and how can I change > it? > > e.g. "if f1==f2:" will always mean "if abs(f1-f2)<1e-6:" > > Anton googled for "floating point" "comparison toleran

Re: Precision for equality of two floats?

2005-11-29 Thread Bengt Richter
On Mon, 28 Nov 2005 07:58:37 -0800, [EMAIL PROTECTED] (Alex Martelli) wrote: >Anton81 <[EMAIL PROTECTED]> wrote: > >> Hi! >> >> When I do simple calculation with float values, they are rarely exactly >> equal even if they should be. What is the threshold and how can I change >> it? > >Python's bu

Re: Precision for equality of two floats?

2005-11-28 Thread Steven D'Aprano
On Mon, 28 Nov 2005 12:35:16 -0500, Mike Meyer wrote: >> e.g. "if f1==f2:" will always mean "if abs(f1-f2)<1e-6:" > > This is a *bad* idea. What happens if f1=1e-12 and f2=1e-112? Do you > really want to values that 100 orders of magnitude different to > compare as equal? Sure, if f1 and f2 rep

Re: Precision for equality of two floats?

2005-11-28 Thread Mike Meyer
Anton81 <[EMAIL PROTECTED]> writes: > When I do simple calculation with float values, they are rarely exactly > equal even if they should be. What is the threshold and how can I change > it? Implementation dependent, because floats use an underlying C type, and there's no portable way to do that.

Re: Precision for equality of two floats?

2005-11-28 Thread Fredrik Lundh
"Anton81" wrote: > When I do simple calculation with float values, they are rarely exactly > equal even if they should be. What is the threshold http://www.lahey.com/float.htm http://docs.python.org/tut/node16.html > and how can I change it? you cannot. > e.g. "if f1==f2:" will always

Re: Precision for equality of two floats?

2005-11-28 Thread Alex Martelli
Anton81 <[EMAIL PROTECTED]> wrote: > Hi! > > When I do simple calculation with float values, they are rarely exactly > equal even if they should be. What is the threshold and how can I change > it? Python's builtin floats compare for exact bit-by-bit equality -- no "threshold". You may want to

Precision for equality of two floats?

2005-11-28 Thread Anton81
Hi! When I do simple calculation with float values, they are rarely exactly equal even if they should be. What is the threshold and how can I change it? e.g. "if f1==f2:" will always mean "if abs(f1-f2)<1e-6:" Anton -- http://mail.python.org/mailman/listinfo/python-list