A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-April/088836.html below:

[Python-Dev] Python-Dev Digest, Vol 69, Issue 143

[Python-Dev] Python-Dev Digest, Vol 69, Issue 143Steven D'Aprano steve at pearwood.info
Fri Apr 17 05:20:12 CEST 2009
On Fri, 17 Apr 2009 12:10:59 pm Tennessee Leeuwenburg wrote:
> Actually, that's a point.
>
> If its' the 31st of Jan, then +1 monthdelta will be 28 Feb and
> another +1 will be 28 March whereas 31st Jan +2 monthdeltas will be
> 31 March.
>
> That's the kind of thing which really needs to be documented, or I
> think people really will make mistakes.

It might be worth noting as an aside, but it should be obvious in the 
same way that string concatenation is different from numerical 
addition:

1 + 2 = 2 + 1
'1' + '2' != '2' + '1'


> For example, should a monthdelta include a goal-day so that the
> example above would go 31 Jan / 28 Feb / 31 March?

No, that just adds complexity.

Consider floating point addition. If you want to step through a loop 
while doing addition, you need to be aware of round-off error:

>>> x = 0.0
>>> step = 0.001
>>> for i in xrange(1000):
...     x += step
...
>>> x
1.0000000000000007

The solution isn't to add a "goal" to the plus operator, but to fix your 
code to use a better algorithm:

>>> y = 0.0
>>> for i in xrange(1, 1001):
...     y = i*step
...
>>> y
1.0

Same with monthdelta.



-- 
Steven D'Aprano
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4