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
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.
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
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)
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.
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
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
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
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
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')
...
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
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
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
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
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
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
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
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
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
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
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)
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) /
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
--
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
--
[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
[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
[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
27 matches
Mail list logo