Re: Floating point bug?

2008-02-16 Thread Steven D'Aprano
On Fri, 15 Feb 2008 17:30:03 -0800, Jeff Schwab wrote: But good advice becomes a superstition when it becomes treated as a law: never test floats for equality. That's simply not true. For example, floats are exact for whole numbers, up to the limits of overflow. That's not true. Epsilon

Re: Floating point bug?

2008-02-16 Thread Dan Bishop
On Feb 14, 8:10 pm, Zentrader [EMAIL PROTECTED] wrote: That's a misconception. The decimal-module has a different base (10 instead of 2), and higher precision. But that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers.

Re: Floating point bug?

2008-02-15 Thread Zentrader
I disagree with this statement quoteBut that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. /quote The example used has no rounding errors. For anything less that 28 significant digits it rounds to 1.0. With floats 1.0/3 yields

Re: Floating point bug?

2008-02-15 Thread Diez B. Roggisch
Zentrader schrieb: That's a misconception. The decimal-module has a different base (10 instead of 2), and higher precision. But that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. import decimal as d d = d.Decimal d(1)

Re: Floating point bug?

2008-02-15 Thread Jeff Schwab
Zentrader wrote: I disagree with this statement quoteBut that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. /quote The example used has no rounding errors. I think we're using the term rounding error to mean different things.

Re: Floating point bug?

2008-02-15 Thread Mark Dickinson
On Feb 15, 3:30 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: The point is that all numbering systems with a base + precision will have (rational) values they can't exactly represent. Q\R is of course out of the question by definition This 'Decimal is exact' myth has been appearing often

Re: Floating point bug?

2008-02-15 Thread Steven D'Aprano
On Fri, 15 Feb 2008 10:55:47 -0800, Zentrader wrote: I disagree with this statement quoteBut that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. /quote The example used has no rounding errors. Of course it does. Three thirds

Re: Floating point bug?

2008-02-15 Thread Jeff Schwab
Steven D'Aprano wrote: On Fri, 15 Feb 2008 10:55:47 -0800, Zentrader wrote: I disagree with this statement quoteBut that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. /quote The example used has no rounding errors. Of

Re: Floating point bug?

2008-02-14 Thread Diez B. Roggisch
Preston Landers schrieb: [EMAIL PROTECTED]([EMAIL PROTECTED])@2008.02.13 15:13:20 -0800: Not a bug. All languages implementing floating point numbers have the same issue. Some just decide to hide it from you. Please read http://docs.python.org/tut/node16.html and particularly

Re: Floating point bug?

2008-02-14 Thread Jeff Schwab
Dennis Lee Bieber wrote: On Wed, 13 Feb 2008 17:49:08 -0800, Jeff Schwab [EMAIL PROTECTED] declaimed the following in comp.lang.python: If you need a pretty string for use in code: def pretty_fp(fpnum, prec=8): ... return ('%.8f' % fpnum).rstrip('0') ...

Re: Floating point bug?

2008-02-14 Thread Christian Heimes
Dennis Lee Bieber wrote: What's wrong with just str(0.3) that's what print invokes, whereas the interpreter prompt is using repr(0.3) No, print invokes the tp_print slot of the float type. Some core types have a special handler for print. The tp_print slot is not

Re: Floating point bug?

2008-02-14 Thread Bruno Desthuilliers
Christian Heimes a écrit : Dennis Lee Bieber wrote: What's wrong with just str(0.3) that's what print invokes, whereas the interpreter prompt is using repr(0.3) No, print invokes the tp_print slot of the float type. Some core types have a special handler for print. The

Re: Floating point bug?

2008-02-14 Thread Christian Heimes
Bruno Desthuilliers wrote: I Must have miss something... Yeah, You have missed the beginning of the third sentence: The tp_print slot is not available from Python code. The tp_print slot is only available in C code and is part of the C definition of a type. Hence tp_ as type. Search for

Re: Floating point bug?

2008-02-14 Thread Duncan Booth
Bruno Desthuilliers [EMAIL PROTECTED] wrote: I Must have miss something... Perhaps you missed the part where Christian said The tp_print slot is not available from Python code? -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating point bug?

2008-02-14 Thread Bruno Desthuilliers
Christian Heimes a écrit : Bruno Desthuilliers wrote: I Must have miss something... Yeah, You have missed the beginning of the third sentence: The tp_print slot is not available from Python code. oops, my bad ! I missed the not !-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating point bug?

2008-02-14 Thread Duncan Booth
Christian Heimes [EMAIL PROTECTED] wrote: Bruno Desthuilliers wrote: I Must have miss something... Yeah, You have missed the beginning of the third sentence: The tp_print slot is not available from Python code. The tp_print slot is only available in C code and is part of the C definition

Re: Floating point bug?

2008-02-14 Thread Jeff Schwab
Christian Heimes wrote: Dennis Lee Bieber wrote: What's wrong with just str(0.3) that's what print invokes, whereas the interpreter prompt is using repr(0.3) No, print invokes the tp_print slot of the float type. Some core types have a special handler for print. The

Re: Floating point bug?

2008-02-14 Thread Gabriel Genellina
En Thu, 14 Feb 2008 15:22:41 -0200, Jeff Schwab [EMAIL PROTECTED] escribió: Christian Heimes wrote: No, print invokes the tp_print slot of the float type. Some core types have a special handler for print. The tp_print slot is not available from Python code and most people don't know about

Re: Floating point bug?

2008-02-14 Thread Duncan Booth
Jeff Schwab [EMAIL PROTECTED] wrote: Christian Heimes wrote: Dennis Lee Bieber wrote: What's wrong with just str(0.3) that's what print invokes, whereas the interpreter prompt is using repr(0.3) No, print invokes the tp_print slot of the float type. Some core types

Re: Floating point bug?

2008-02-14 Thread robinsiebler
I did try searching, but I never found what I was looking for. This thread has been very useful and informative. Thanks for all your help! I was able to fix my problem. :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Floating point bug?

2008-02-14 Thread Zentrader
That's a misconception. The decimal-module has a different base (10 instead of 2), and higher precision. But that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. import decimal as d d = d.Decimal d(1) / d(3) * d(3)

Re: Floating point bug?

2008-02-14 Thread Jeff Schwab
Zentrader wrote: That's a misconception. The decimal-module has a different base (10 instead of 2), and higher precision. But that doesn't change the fact that it will expose the same rounding-errors as floats do - just for different numbers. import decimal as d d = d.Decimal d(1) /

Floating point bug?

2008-02-13 Thread robinsiebler
I've never had any call to use floating point numbers and now that I want to, I can't! *** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32. *** float (.3) 0.2 foo = 0.3 foo 0.2 --

Re: Floating point bug?

2008-02-13 Thread marek . rocki
Not a bug. All languages implementing floating point numbers have the same issue. Some just decide to hide it from you. Please read http://docs.python.org/tut/node16.html and particularly http://docs.python.org/tut/node16.html#SECTION001610 Regards, Marek --

Re: Floating point bug?

2008-02-13 Thread Preston Landers
[EMAIL PROTECTED]([EMAIL PROTECTED])@2008.02.13 15:13:20 -0800: Not a bug. All languages implementing floating point numbers have the same issue. Some just decide to hide it from you. Please read http://docs.python.org/tut/node16.html and particularly

Re: Floating point bug?

2008-02-13 Thread Bjoern Schliessmann
[EMAIL PROTECTED] wrote: I've never had any call to use floating point numbers and now that I want to, I can't! Ever considered phrasing your actual problem so one can help, let alone looking at the archive for many, many postings about this topic? Regards, Björn -- BOFH excuse #66: bit

Re: Floating point bug?

2008-02-13 Thread Jeff Schwab
[EMAIL PROTECTED] wrote: I've never had any call to use floating point numbers and now that I want to, I can't! *** Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit (Intel)] on win32. *** float (.3) 0.2 foo = 0.3 foo 0.2 A classic (if