Merged revisions 59512-59540 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r59513 | raymond.hettinger | 2007-12-15 01:07:25 +0100 (Sat, 15 Dec 2007) | 6 lines Optimize PyList_AsTuple(). Improve cache performance by doing the pointer copy and object increment in one pass. For small lists, save the overhead of the call to memcpy() -- this comes up in calls like f(*listcomp). ........ r59519 | christian.heimes | 2007-12-15 06:38:35 +0100 (Sat, 15 Dec 2007) | 2 lines Fixed #1624: Remove output comparison for test_pep277 I had to modify Brett's patch slightly. ........ r59520 | georg.brandl | 2007-12-15 10:34:59 +0100 (Sat, 15 Dec 2007) | 2 lines Add note about future import needed for with statement. ........ r59522 | georg.brandl | 2007-12-15 10:36:37 +0100 (Sat, 15 Dec 2007) | 2 lines Argh, wrong version. ........ r59524 | georg.brandl | 2007-12-16 12:06:09 +0100 (Sun, 16 Dec 2007) | 2 lines Dummy commit to investigate #1617. ........ r59525 | georg.brandl | 2007-12-16 12:21:48 +0100 (Sun, 16 Dec 2007) | 2 lines Revert dummy commit now that the build slave is building. ........ r59527 | georg.brandl | 2007-12-16 16:47:46 +0100 (Sun, 16 Dec 2007) | 2 lines Remove orphaned footnote reference. ........ r59528 | georg.brandl | 2007-12-16 16:53:49 +0100 (Sun, 16 Dec 2007) | 2 lines Remove gratuitous unicode character. ........ r59529 | georg.brandl | 2007-12-16 16:59:19 +0100 (Sun, 16 Dec 2007) | 2 lines Remove another unnecessary Unicode character. ........ r59530 | georg.brandl | 2007-12-16 17:00:36 +0100 (Sun, 16 Dec 2007) | 2 lines Remove curious space-like characters. ........ r59532 | georg.brandl | 2007-12-16 20:36:51 +0100 (Sun, 16 Dec 2007) | 2 lines Adapt conf.py to new option names. ........ r59533 | christian.heimes | 2007-12-16 22:39:43 +0100 (Sun, 16 Dec 2007) | 1 line Fixed #1638: %zd configure test fails on Linux ........ r59536 | georg.brandl | 2007-12-17 00:11:16 +0100 (Mon, 17 Dec 2007) | 2 lines Simplify. ........ r59537 | georg.brandl | 2007-12-17 00:13:29 +0100 (Mon, 17 Dec 2007) | 2 lines Use PEP 8. ........ r59539 | georg.brandl | 2007-12-17 00:15:07 +0100 (Mon, 17 Dec 2007) | 2 lines Don't use quotes for non-string code. ........ r59540 | facundo.batista | 2007-12-17 15:18:42 +0100 (Mon, 17 Dec 2007) | 4 lines Removed the private _rounding_decision: it was not needed, and the code is now simpler. Thanks Mark Dickinson. ........
This commit is contained in:
parent
3377055486
commit
2c18161606
11
Doc/Makefile
11
Doc/Makefile
|
@ -7,16 +7,19 @@
|
||||||
PYTHON = python2.5
|
PYTHON = python2.5
|
||||||
SVNROOT = http://svn.python.org/projects
|
SVNROOT = http://svn.python.org/projects
|
||||||
SPHINXOPTS =
|
SPHINXOPTS =
|
||||||
|
PAPER =
|
||||||
|
|
||||||
ALLSPHINXOPTS = -b$(BUILDER) -dbuild/doctrees $(SPHINXOPTS) . build/$(BUILDER)
|
ALLSPHINXOPTS = -b $(BUILDER) -d build/doctrees -D latex_paper_size=$(PAPER) \
|
||||||
|
$(SPHINXOPTS) . build/$(BUILDER)
|
||||||
|
|
||||||
.PHONY: help checkout update build html web htmlhelp clean
|
.PHONY: help checkout update build html web htmlhelp clean
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@echo "Please use \`make <target>' where <target> is one of"
|
@echo "Please use \`make <target>' where <target> is one of"
|
||||||
@echo " html to make standalone HTML files"
|
@echo " html to make standalone HTML files"
|
||||||
@echo " web to make file usable by Sphinx.web"
|
@echo " web to make file usable by Sphinx.web"
|
||||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||||
|
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||||
|
|
||||||
checkout:
|
checkout:
|
||||||
@if [ ! -d tools/sphinx ]; then \
|
@if [ ! -d tools/sphinx ]; then \
|
||||||
|
@ -60,6 +63,8 @@ htmlhelp: build
|
||||||
latex: BUILDER = latex
|
latex: BUILDER = latex
|
||||||
latex: build
|
latex: build
|
||||||
@echo "Build finished; the LaTeX files are in build/latex."
|
@echo "Build finished; the LaTeX files are in build/latex."
|
||||||
|
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
|
||||||
|
"run these through (pdf)latex."
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -rf build/*
|
-rm -rf build/*
|
||||||
|
|
40
Doc/conf.py
40
Doc/conf.py
|
@ -4,7 +4,9 @@
|
||||||
#
|
#
|
||||||
# The contents of this file are pickled, so don't put values in the namespace
|
# The contents of this file are pickled, so don't put values in the namespace
|
||||||
# that aren't pickleable (module imports are okay, they're removed automatically).
|
# that aren't pickleable (module imports are okay, they're removed automatically).
|
||||||
#
|
|
||||||
|
# General configuration
|
||||||
|
# ---------------------
|
||||||
|
|
||||||
# The default replacements for |version| and |release|.
|
# The default replacements for |version| and |release|.
|
||||||
# If 'auto', Sphinx looks for the Include/patchlevel.h file in the current Python
|
# If 'auto', Sphinx looks for the Include/patchlevel.h file in the current Python
|
||||||
|
@ -23,9 +25,6 @@ today = ''
|
||||||
# Else, today_fmt is used as the format for a strftime call.
|
# Else, today_fmt is used as the format for a strftime call.
|
||||||
today_fmt = '%B %d, %Y'
|
today_fmt = '%B %d, %Y'
|
||||||
|
|
||||||
# The base URL for download links.
|
|
||||||
download_base_url = 'http://docs.python.org/ftp/python/doc/'
|
|
||||||
|
|
||||||
# List of files that shouldn't be included in the build.
|
# List of files that shouldn't be included in the build.
|
||||||
unused_files = [
|
unused_files = [
|
||||||
'whatsnew/2.0.rst',
|
'whatsnew/2.0.rst',
|
||||||
|
@ -40,17 +39,34 @@ unused_files = [
|
||||||
'library/xml.etree.rst',
|
'library/xml.etree.rst',
|
||||||
]
|
]
|
||||||
|
|
||||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
|
||||||
# using the given strftime format.
|
|
||||||
last_updated_format = '%b %d, %Y'
|
|
||||||
|
|
||||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
|
||||||
# typographically correct entities.
|
|
||||||
use_smartypants = True
|
|
||||||
|
|
||||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||||
add_function_parentheses = True
|
add_function_parentheses = True
|
||||||
|
|
||||||
# If true, the current module name will be prepended to all description
|
# If true, the current module name will be prepended to all description
|
||||||
# unit titles (such as .. function::).
|
# unit titles (such as .. function::).
|
||||||
add_module_names = True
|
add_module_names = True
|
||||||
|
|
||||||
|
|
||||||
|
# Options for HTML output
|
||||||
|
# -----------------------
|
||||||
|
|
||||||
|
# The base URL for download links.
|
||||||
|
html_download_base_url = 'http://docs.python.org/ftp/python/doc/'
|
||||||
|
|
||||||
|
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||||
|
# using the given strftime format.
|
||||||
|
html_last_updated_fmt = '%b %d, %Y'
|
||||||
|
|
||||||
|
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||||
|
# typographically correct entities.
|
||||||
|
html_use_smartypants = True
|
||||||
|
|
||||||
|
|
||||||
|
# Options for LaTeX output
|
||||||
|
# ------------------------
|
||||||
|
|
||||||
|
# The paper size ("letter" or "a4").
|
||||||
|
latex_paper_size = "a4"
|
||||||
|
|
||||||
|
# The font size ("10pt", "11pt" or "12pt").
|
||||||
|
latex_font_size = "10pt"
|
||||||
|
|
|
@ -16,7 +16,7 @@ Names for built-in exceptions and functions and a number of constants are found
|
||||||
in a separate symbol table. This table is searched last when the interpreter
|
in a separate symbol table. This table is searched last when the interpreter
|
||||||
looks up the meaning of a name, so local and global user-defined names can
|
looks up the meaning of a name, so local and global user-defined names can
|
||||||
override built-in names. Built-in types are described together here for easy
|
override built-in names. Built-in types are described together here for easy
|
||||||
reference. [#]_
|
reference.
|
||||||
|
|
||||||
The tables in this chapter document the priorities of operators by listing them
|
The tables in this chapter document the priorities of operators by listing them
|
||||||
in order of ascending priority (within a table) and grouping operators that have
|
in order of ascending priority (within a table) and grouping operators that have
|
||||||
|
|
|
@ -63,14 +63,14 @@ also available for Python:
|
||||||
`wxPython <http://www.wxpython.org>`_
|
`wxPython <http://www.wxpython.org>`_
|
||||||
wxPython is a cross-platform GUI toolkit for Python that is built around
|
wxPython is a cross-platform GUI toolkit for Python that is built around
|
||||||
the popular `wxWidgets <http://www.wxwidgets.org/>`_ (formerly wxWindows)
|
the popular `wxWidgets <http://www.wxwidgets.org/>`_ (formerly wxWindows)
|
||||||
C++ toolkit. It provides a native look and feel for applications on
|
C++ toolkit. It provides a native look and feel for applications on
|
||||||
Windows, Mac OS X, and Unix systems by using each platform's native
|
Windows, Mac OS X, and Unix systems by using each platform's native
|
||||||
widgets where ever possible, (GTK+ on Unix-like systems). In addition to
|
widgets where ever possible, (GTK+ on Unix-like systems). In addition to
|
||||||
an extensive set of widgets, wxPython provides classes for online
|
an extensive set of widgets, wxPython provides classes for online
|
||||||
documentation and context sensitive help, printing, HTML viewing,
|
documentation and context sensitive help, printing, HTML viewing,
|
||||||
low-level device context drawing, drag and drop, system clipboard access,
|
low-level device context drawing, drag and drop, system clipboard access,
|
||||||
an XML-based resource format and more, including an ever growing library
|
an XML-based resource format and more, including an ever growing library
|
||||||
of user-contributed modules. wxPython has a book, `wxPython in Action
|
of user-contributed modules. wxPython has a book, `wxPython in Action
|
||||||
<http://www.amazon.com/exec/obidos/ASIN/1932394621>`_, by Noel Rappin and
|
<http://www.amazon.com/exec/obidos/ASIN/1932394621>`_, by Noel Rappin and
|
||||||
Robin Dunn.
|
Robin Dunn.
|
||||||
|
|
||||||
|
|
|
@ -608,7 +608,7 @@ Notes:
|
||||||
|
|
||||||
(5)
|
(5)
|
||||||
The slice of *s* from *i* to *j* with step *k* is defined as the sequence of
|
The slice of *s* from *i* to *j* with step *k* is defined as the sequence of
|
||||||
items with index ``x = i + n*k`` such that 0 ≤n < (j-i)/(k). In other words,
|
items with index ``x = i + n*k`` such that ``0 <= n < (j-i)/k``. In other words,
|
||||||
the indices are ``i``, ``i+k``, ``i+2*k``, ``i+3*k`` and so on, stopping when
|
the indices are ``i``, ``i+k``, ``i+2*k``, ``i+3*k`` and so on, stopping when
|
||||||
*j* is reached (but never including *j*). If *i* or *j* is greater than
|
*j* is reached (but never including *j*). If *i* or *j* is greater than
|
||||||
``len(s)``, use ``len(s)``. If *i* or *j* are omitted or ``None``, they become
|
``len(s)``, use ``len(s)``. If *i* or *j* are omitted or ``None``, they become
|
||||||
|
|
|
@ -285,5 +285,5 @@ corresponding to a full circle:
|
||||||
.. method:: Turtle.degrees([fullcircle])
|
.. method:: Turtle.degrees([fullcircle])
|
||||||
|
|
||||||
*fullcircle* is by default 360. This can cause the pen to have any angular units
|
*fullcircle* is by default 360. This can cause the pen to have any angular units
|
||||||
whatever: give *fullcircle* 2\*$π for radians, or 400 for gradians.
|
whatever: give *fullcircle* ``2*pi`` for radians, or 400 for gradians.
|
||||||
|
|
||||||
|
|
|
@ -276,9 +276,7 @@ releases are built, the source tree contains solutions/project files. View the
|
||||||
+--------------------+--------------+-----------------------+
|
+--------------------+--------------+-----------------------+
|
||||||
| Directory | MSVC version | Visual Studio version |
|
| Directory | MSVC version | Visual Studio version |
|
||||||
+====================+==============+=======================+
|
+====================+==============+=======================+
|
||||||
| :file:`PC/VC6/` | 5.0 | 97 |
|
| :file:`PC/VC6/` | 6.0 | 97 |
|
||||||
| +--------------+-----------------------+
|
|
||||||
| | 6.0 | 6.0 |
|
|
||||||
+--------------------+--------------+-----------------------+
|
+--------------------+--------------+-----------------------+
|
||||||
| :file:`PCbuild/` | 7.1 | 2003 |
|
| :file:`PCbuild/` | 7.1 | 2003 |
|
||||||
+--------------------+--------------+-----------------------+
|
+--------------------+--------------+-----------------------+
|
||||||
|
|
|
@ -202,7 +202,7 @@ A high-level explanation of the context management protocol is:
|
||||||
methods.
|
methods.
|
||||||
|
|
||||||
* The context manager's :meth:`__enter__` method is called. The value returned
|
* The context manager's :meth:`__enter__` method is called. The value returned
|
||||||
is assigned to *VAR*. If no ``'as VAR'`` clause is present, the value is simply
|
is assigned to *VAR*. If no ``as VAR`` clause is present, the value is simply
|
||||||
discarded.
|
discarded.
|
||||||
|
|
||||||
* The code in *BLOCK* is executed.
|
* The code in *BLOCK* is executed.
|
||||||
|
@ -242,11 +242,11 @@ rolled back if there's an exception. Here's the basic interface for
|
||||||
|
|
||||||
class DatabaseConnection:
|
class DatabaseConnection:
|
||||||
# Database interface
|
# Database interface
|
||||||
def cursor (self):
|
def cursor(self):
|
||||||
"Returns a cursor object and starts a new transaction"
|
"Returns a cursor object and starts a new transaction"
|
||||||
def commit (self):
|
def commit(self):
|
||||||
"Commits current transaction"
|
"Commits current transaction"
|
||||||
def rollback (self):
|
def rollback(self):
|
||||||
"Rolls back current transaction"
|
"Rolls back current transaction"
|
||||||
|
|
||||||
The :meth:`__enter__` method is pretty easy, having only to start a new
|
The :meth:`__enter__` method is pretty easy, having only to start a new
|
||||||
|
@ -256,7 +256,7 @@ their ':keyword:`with`' statement to bind the cursor to a variable name. ::
|
||||||
|
|
||||||
class DatabaseConnection:
|
class DatabaseConnection:
|
||||||
...
|
...
|
||||||
def __enter__ (self):
|
def __enter__(self):
|
||||||
# Code to start a new transaction
|
# Code to start a new transaction
|
||||||
cursor = self.cursor()
|
cursor = self.cursor()
|
||||||
return cursor
|
return cursor
|
||||||
|
@ -273,7 +273,7 @@ add a :keyword:`return` statement at the marked location. ::
|
||||||
|
|
||||||
class DatabaseConnection:
|
class DatabaseConnection:
|
||||||
...
|
...
|
||||||
def __exit__ (self, type, value, tb):
|
def __exit__(self, type, value, tb):
|
||||||
if tb is None:
|
if tb is None:
|
||||||
# No exception, so commit
|
# No exception, so commit
|
||||||
self.commit()
|
self.commit()
|
||||||
|
@ -306,7 +306,7 @@ decorator as::
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def db_transaction (connection):
|
def db_transaction(connection):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
try:
|
try:
|
||||||
yield cursor
|
yield cursor
|
||||||
|
|
132
Lib/decimal.py
132
Lib/decimal.py
|
@ -147,10 +147,6 @@ ROUND_UP = 'ROUND_UP'
|
||||||
ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
|
ROUND_HALF_DOWN = 'ROUND_HALF_DOWN'
|
||||||
ROUND_05UP = 'ROUND_05UP'
|
ROUND_05UP = 'ROUND_05UP'
|
||||||
|
|
||||||
# Rounding decision (not part of the public API)
|
|
||||||
NEVER_ROUND = 'NEVER_ROUND' # Round in division (non-divmod), sqrt ONLY
|
|
||||||
ALWAYS_ROUND = 'ALWAYS_ROUND' # Every operation rounds at end.
|
|
||||||
|
|
||||||
# Errors
|
# Errors
|
||||||
|
|
||||||
class DecimalException(ArithmeticError):
|
class DecimalException(ArithmeticError):
|
||||||
|
@ -932,9 +928,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
|
|
||||||
if context is None:
|
if context is None:
|
||||||
context = getcontext()
|
context = getcontext()
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def __pos__(self, context=None):
|
def __pos__(self, context=None):
|
||||||
"""Returns a copy, unless it is a sNaN.
|
"""Returns a copy, unless it is a sNaN.
|
||||||
|
@ -954,26 +948,23 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
|
|
||||||
if context is None:
|
if context is None:
|
||||||
context = getcontext()
|
context = getcontext()
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def __abs__(self, round=1, context=None):
|
def __abs__(self, round=True, context=None):
|
||||||
"""Returns the absolute value of self.
|
"""Returns the absolute value of self.
|
||||||
|
|
||||||
If the second argument is 0, do not round.
|
If the keyword argument 'round' is false, do not round. The
|
||||||
|
expression self.__abs__(round=False) is equivalent to
|
||||||
|
self.copy_abs().
|
||||||
"""
|
"""
|
||||||
|
if not round:
|
||||||
|
return self.copy_abs()
|
||||||
|
|
||||||
if self._is_special:
|
if self._is_special:
|
||||||
ans = self._check_nans(context=context)
|
ans = self._check_nans(context=context)
|
||||||
if ans:
|
if ans:
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
if not round:
|
|
||||||
if context is None:
|
|
||||||
context = getcontext()
|
|
||||||
context = context._shallow_copy()
|
|
||||||
context._set_rounding_decision(NEVER_ROUND)
|
|
||||||
|
|
||||||
if self._sign:
|
if self._sign:
|
||||||
ans = self.__neg__(context=context)
|
ans = self.__neg__(context=context)
|
||||||
else:
|
else:
|
||||||
|
@ -1006,8 +997,6 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
if other._isinfinity():
|
if other._isinfinity():
|
||||||
return Decimal(other) # Can't both be infinity here
|
return Decimal(other) # Can't both be infinity here
|
||||||
|
|
||||||
shouldround = context._rounding_decision == ALWAYS_ROUND
|
|
||||||
|
|
||||||
exp = min(self._exp, other._exp)
|
exp = min(self._exp, other._exp)
|
||||||
negativezero = 0
|
negativezero = 0
|
||||||
if context.rounding == ROUND_FLOOR and self._sign != other._sign:
|
if context.rounding == ROUND_FLOOR and self._sign != other._sign:
|
||||||
|
@ -1019,33 +1008,29 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
if negativezero:
|
if negativezero:
|
||||||
sign = 1
|
sign = 1
|
||||||
ans = _dec_from_triple(sign, '0', exp)
|
ans = _dec_from_triple(sign, '0', exp)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
if not self:
|
if not self:
|
||||||
exp = max(exp, other._exp - context.prec-1)
|
exp = max(exp, other._exp - context.prec-1)
|
||||||
ans = other._rescale(exp, context.rounding)
|
ans = other._rescale(exp, context.rounding)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
if not other:
|
if not other:
|
||||||
exp = max(exp, self._exp - context.prec-1)
|
exp = max(exp, self._exp - context.prec-1)
|
||||||
ans = self._rescale(exp, context.rounding)
|
ans = self._rescale(exp, context.rounding)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
op1 = _WorkRep(self)
|
op1 = _WorkRep(self)
|
||||||
op2 = _WorkRep(other)
|
op2 = _WorkRep(other)
|
||||||
op1, op2 = _normalize(op1, op2, shouldround, context.prec)
|
op1, op2 = _normalize(op1, op2, context.prec)
|
||||||
|
|
||||||
result = _WorkRep()
|
result = _WorkRep()
|
||||||
if op1.sign != op2.sign:
|
if op1.sign != op2.sign:
|
||||||
# Equal and opposite
|
# Equal and opposite
|
||||||
if op1.int == op2.int:
|
if op1.int == op2.int:
|
||||||
ans = _dec_from_triple(negativezero, '0', exp)
|
ans = _dec_from_triple(negativezero, '0', exp)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
if op1.int < op2.int:
|
if op1.int < op2.int:
|
||||||
op1, op2 = op2, op1
|
op1, op2 = op2, op1
|
||||||
|
@ -1070,8 +1055,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
|
|
||||||
result.exp = op1.exp
|
result.exp = op1.exp
|
||||||
ans = Decimal(result)
|
ans = Decimal(result)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
__radd__ = __add__
|
__radd__ = __add__
|
||||||
|
@ -1128,34 +1112,29 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
return Infsign[resultsign]
|
return Infsign[resultsign]
|
||||||
|
|
||||||
resultexp = self._exp + other._exp
|
resultexp = self._exp + other._exp
|
||||||
shouldround = context._rounding_decision == ALWAYS_ROUND
|
|
||||||
|
|
||||||
# Special case for multiplying by zero
|
# Special case for multiplying by zero
|
||||||
if not self or not other:
|
if not self or not other:
|
||||||
ans = _dec_from_triple(resultsign, '0', resultexp)
|
ans = _dec_from_triple(resultsign, '0', resultexp)
|
||||||
if shouldround:
|
# Fixing in case the exponent is out of bounds
|
||||||
# Fixing in case the exponent is out of bounds
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
# Special case for multiplying by power of 10
|
# Special case for multiplying by power of 10
|
||||||
if self._int == '1':
|
if self._int == '1':
|
||||||
ans = _dec_from_triple(resultsign, other._int, resultexp)
|
ans = _dec_from_triple(resultsign, other._int, resultexp)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
if other._int == '1':
|
if other._int == '1':
|
||||||
ans = _dec_from_triple(resultsign, self._int, resultexp)
|
ans = _dec_from_triple(resultsign, self._int, resultexp)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
op1 = _WorkRep(self)
|
op1 = _WorkRep(self)
|
||||||
op2 = _WorkRep(other)
|
op2 = _WorkRep(other)
|
||||||
|
|
||||||
ans = _dec_from_triple(resultsign, str(op1.int * op2.int), resultexp)
|
ans = _dec_from_triple(resultsign, str(op1.int * op2.int), resultexp)
|
||||||
if shouldround:
|
ans = ans._fix(context)
|
||||||
ans = ans._fix(context)
|
|
||||||
|
|
||||||
return ans
|
return ans
|
||||||
__rmul__ = __mul__
|
__rmul__ = __mul__
|
||||||
|
@ -1292,8 +1271,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
context._raise_error(InvalidOperation, 'x % 0'))
|
context._raise_error(InvalidOperation, 'x % 0'))
|
||||||
|
|
||||||
quotient, remainder = self._divide(other, context)
|
quotient, remainder = self._divide(other, context)
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
remainder = remainder._fix(context)
|
||||||
remainder = remainder._fix(context)
|
|
||||||
return quotient, remainder
|
return quotient, remainder
|
||||||
|
|
||||||
def __rdivmod__(self, other, context=None):
|
def __rdivmod__(self, other, context=None):
|
||||||
|
@ -1327,8 +1305,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
return context._raise_error(DivisionUndefined, '0 % 0')
|
return context._raise_error(DivisionUndefined, '0 % 0')
|
||||||
|
|
||||||
remainder = self._divide(other, context)[1]
|
remainder = self._divide(other, context)[1]
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
remainder = remainder._fix(context)
|
||||||
remainder = remainder._fix(context)
|
|
||||||
return remainder
|
return remainder
|
||||||
|
|
||||||
def __rmod__(self, other, context=None):
|
def __rmod__(self, other, context=None):
|
||||||
|
@ -2498,9 +2475,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
else:
|
else:
|
||||||
ans = self
|
ans = self
|
||||||
|
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def min(self, other, context=None):
|
def min(self, other, context=None):
|
||||||
"""Returns the smaller value.
|
"""Returns the smaller value.
|
||||||
|
@ -2534,9 +2509,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
else:
|
else:
|
||||||
ans = other
|
ans = other
|
||||||
|
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def _isinteger(self):
|
def _isinteger(self):
|
||||||
"""Returns whether self is an integer"""
|
"""Returns whether self is an integer"""
|
||||||
|
@ -3107,9 +3080,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
else:
|
else:
|
||||||
ans = self
|
ans = self
|
||||||
|
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def min_mag(self, other, context=None):
|
def min_mag(self, other, context=None):
|
||||||
"""Compares the values numerically with their sign ignored."""
|
"""Compares the values numerically with their sign ignored."""
|
||||||
|
@ -3139,9 +3110,7 @@ class Decimal(_numbers.Real, _numbers.Inexact):
|
||||||
else:
|
else:
|
||||||
ans = other
|
ans = other
|
||||||
|
|
||||||
if context._rounding_decision == ALWAYS_ROUND:
|
return ans._fix(context)
|
||||||
return ans._fix(context)
|
|
||||||
return ans
|
|
||||||
|
|
||||||
def next_minus(self, context=None):
|
def next_minus(self, context=None):
|
||||||
"""Returns the largest representable number smaller than itself."""
|
"""Returns the largest representable number smaller than itself."""
|
||||||
|
@ -3434,7 +3403,6 @@ class Context(object):
|
||||||
Contains:
|
Contains:
|
||||||
prec - precision (for use in rounding, division, square roots..)
|
prec - precision (for use in rounding, division, square roots..)
|
||||||
rounding - rounding type (how you round)
|
rounding - rounding type (how you round)
|
||||||
_rounding_decision - ALWAYS_ROUND, NEVER_ROUND -- do you round?
|
|
||||||
traps - If traps[exception] = 1, then the exception is
|
traps - If traps[exception] = 1, then the exception is
|
||||||
raised when it is caused. Otherwise, a value is
|
raised when it is caused. Otherwise, a value is
|
||||||
substituted in.
|
substituted in.
|
||||||
|
@ -3450,7 +3418,6 @@ class Context(object):
|
||||||
|
|
||||||
def __init__(self, prec=None, rounding=None,
|
def __init__(self, prec=None, rounding=None,
|
||||||
traps=None, flags=None,
|
traps=None, flags=None,
|
||||||
_rounding_decision=None,
|
|
||||||
Emin=None, Emax=None,
|
Emin=None, Emax=None,
|
||||||
capitals=None, _clamp=0,
|
capitals=None, _clamp=0,
|
||||||
_ignored_flags=None):
|
_ignored_flags=None):
|
||||||
|
@ -3488,16 +3455,16 @@ class Context(object):
|
||||||
|
|
||||||
def _shallow_copy(self):
|
def _shallow_copy(self):
|
||||||
"""Returns a shallow copy from self."""
|
"""Returns a shallow copy from self."""
|
||||||
nc = Context(self.prec, self.rounding, self.traps, self.flags,
|
nc = Context(self.prec, self.rounding, self.traps,
|
||||||
self._rounding_decision, self.Emin, self.Emax,
|
self.flags, self.Emin, self.Emax,
|
||||||
self.capitals, self._clamp, self._ignored_flags)
|
self.capitals, self._clamp, self._ignored_flags)
|
||||||
return nc
|
return nc
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
"""Returns a deep copy from self."""
|
"""Returns a deep copy from self."""
|
||||||
nc = Context(self.prec, self.rounding, self.traps.copy(),
|
nc = Context(self.prec, self.rounding, self.traps.copy(),
|
||||||
self.flags.copy(), self._rounding_decision, self.Emin,
|
self.flags.copy(), self.Emin, self.Emax,
|
||||||
self.Emax, self.capitals, self._clamp, self._ignored_flags)
|
self.capitals, self._clamp, self._ignored_flags)
|
||||||
return nc
|
return nc
|
||||||
__copy__ = copy
|
__copy__ = copy
|
||||||
|
|
||||||
|
@ -3554,27 +3521,6 @@ class Context(object):
|
||||||
"""Returns maximum exponent (= Emax - prec + 1)"""
|
"""Returns maximum exponent (= Emax - prec + 1)"""
|
||||||
return int(self.Emax - self.prec + 1)
|
return int(self.Emax - self.prec + 1)
|
||||||
|
|
||||||
def _set_rounding_decision(self, type):
|
|
||||||
"""Sets the rounding decision.
|
|
||||||
|
|
||||||
Sets the rounding decision, and returns the current (previous)
|
|
||||||
rounding decision. Often used like:
|
|
||||||
|
|
||||||
context = context._shallow_copy()
|
|
||||||
# That so you don't change the calling context
|
|
||||||
# if an error occurs in the middle (say DivisionImpossible is raised).
|
|
||||||
|
|
||||||
rounding = context._set_rounding_decision(NEVER_ROUND)
|
|
||||||
instance = instance / Decimal(2)
|
|
||||||
context._set_rounding_decision(rounding)
|
|
||||||
|
|
||||||
This will make it not round for that operation.
|
|
||||||
"""
|
|
||||||
|
|
||||||
rounding = self._rounding_decision
|
|
||||||
self._rounding_decision = type
|
|
||||||
return rounding
|
|
||||||
|
|
||||||
def _set_rounding(self, type):
|
def _set_rounding(self, type):
|
||||||
"""Sets the rounding type.
|
"""Sets the rounding type.
|
||||||
|
|
||||||
|
@ -4762,7 +4708,7 @@ class _WorkRep(object):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _normalize(op1, op2, shouldround = 0, prec = 0):
|
def _normalize(op1, op2, prec = 0):
|
||||||
"""Normalizes op1, op2 to have the same exp and length of coefficient.
|
"""Normalizes op1, op2 to have the same exp and length of coefficient.
|
||||||
|
|
||||||
Done during addition.
|
Done during addition.
|
||||||
|
@ -4779,13 +4725,12 @@ def _normalize(op1, op2, shouldround = 0, prec = 0):
|
||||||
# as adding any positive quantity smaller than 10**exp; similarly
|
# as adding any positive quantity smaller than 10**exp; similarly
|
||||||
# for subtraction. So if other is smaller than 10**exp we replace
|
# for subtraction. So if other is smaller than 10**exp we replace
|
||||||
# it with 10**exp. This avoids tmp.exp - other.exp getting too large.
|
# it with 10**exp. This avoids tmp.exp - other.exp getting too large.
|
||||||
if shouldround:
|
tmp_len = len(str(tmp.int))
|
||||||
tmp_len = len(str(tmp.int))
|
other_len = len(str(other.int))
|
||||||
other_len = len(str(other.int))
|
exp = tmp.exp + min(-1, tmp_len - prec - 2)
|
||||||
exp = tmp.exp + min(-1, tmp_len - prec - 2)
|
if other_len + other.exp - 1 < exp:
|
||||||
if other_len + other.exp - 1 < exp:
|
other.int = 1
|
||||||
other.int = 1
|
other.exp = exp
|
||||||
other.exp = exp
|
|
||||||
|
|
||||||
tmp.int *= 10 ** (tmp.exp - other.exp)
|
tmp.int *= 10 ** (tmp.exp - other.exp)
|
||||||
tmp.exp = other.exp
|
tmp.exp = other.exp
|
||||||
|
@ -5153,7 +5098,6 @@ DefaultContext = Context(
|
||||||
prec=28, rounding=ROUND_HALF_EVEN,
|
prec=28, rounding=ROUND_HALF_EVEN,
|
||||||
traps=[DivisionByZero, Overflow, InvalidOperation],
|
traps=[DivisionByZero, Overflow, InvalidOperation],
|
||||||
flags=[],
|
flags=[],
|
||||||
_rounding_decision=ALWAYS_ROUND,
|
|
||||||
Emax=999999999,
|
Emax=999999999,
|
||||||
Emin=-999999999,
|
Emin=-999999999,
|
||||||
capitals=1
|
capitals=1
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
test_pep277
|
|
||||||
'\xdf-\u66e8\u66e9\u66eb'
|
|
||||||
['Gr\xfc\xdf-Gott', 'abc', 'ascii', '\u0393\u03b5\u03b9\u03ac-\u03c3\u03b1\u03c2', '\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439\u0442\u0435', '\u05d4\u05e9\u05e7\u05e6\u05e5\u05e1', '\u306b\u307d\u3093', '\u66e8\u05e9\u3093\u0434\u0393\xdf', '\u66e8\u66e9\u66eb']
|
|
|
@ -78,12 +78,12 @@ class UnicodeFileTests(unittest.TestCase):
|
||||||
|
|
||||||
def test_listdir(self):
|
def test_listdir(self):
|
||||||
f1 = os.listdir(test_support.TESTFN)
|
f1 = os.listdir(test_support.TESTFN)
|
||||||
# Printing f1 is not appropriate, as specific filenames
|
|
||||||
# returned depend on the local encoding
|
|
||||||
f2 = os.listdir(str(test_support.TESTFN.encode("utf-8"),
|
f2 = os.listdir(str(test_support.TESTFN.encode("utf-8"),
|
||||||
sys.getfilesystemencoding()))
|
sys.getfilesystemencoding()))
|
||||||
f2.sort()
|
sf2 = set("\\".join((unicode(test_support.TESTFN), f))
|
||||||
print(f2)
|
for f in f2)
|
||||||
|
self.failUnlessEqual(len(f1), len(self.files))
|
||||||
|
self.failUnlessEqual(sf2, set(self.files))
|
||||||
|
|
||||||
def test_rename(self):
|
def test_rename(self):
|
||||||
for name in self.files:
|
for name in self.files:
|
||||||
|
@ -99,7 +99,6 @@ class UnicodeFileTests(unittest.TestCase):
|
||||||
f = open(filename, 'wb')
|
f = open(filename, 'wb')
|
||||||
f.write((filename + '\n').encode("utf-8"))
|
f.write((filename + '\n').encode("utf-8"))
|
||||||
f.close()
|
f.close()
|
||||||
print(repr(filename))
|
|
||||||
os.access(filename,os.R_OK)
|
os.access(filename,os.R_OK)
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
os.chdir(oldwd)
|
os.chdir(oldwd)
|
||||||
|
|
|
@ -2177,7 +2177,7 @@ PyObject *
|
||||||
PyList_AsTuple(PyObject *v)
|
PyList_AsTuple(PyObject *v)
|
||||||
{
|
{
|
||||||
PyObject *w;
|
PyObject *w;
|
||||||
PyObject **p;
|
PyObject **p, **q;
|
||||||
Py_ssize_t n;
|
Py_ssize_t n;
|
||||||
if (v == NULL || !PyList_Check(v)) {
|
if (v == NULL || !PyList_Check(v)) {
|
||||||
PyErr_BadInternalCall();
|
PyErr_BadInternalCall();
|
||||||
|
@ -2188,12 +2188,12 @@ PyList_AsTuple(PyObject *v)
|
||||||
if (w == NULL)
|
if (w == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
p = ((PyTupleObject *)w)->ob_item;
|
p = ((PyTupleObject *)w)->ob_item;
|
||||||
memcpy((void *)p,
|
q = ((PyListObject *)v)->ob_item;
|
||||||
(void *)((PyListObject *)v)->ob_item,
|
|
||||||
n*sizeof(PyObject *));
|
|
||||||
while (--n >= 0) {
|
while (--n >= 0) {
|
||||||
Py_INCREF(*p);
|
Py_INCREF(*q);
|
||||||
|
*p = *q;
|
||||||
p++;
|
p++;
|
||||||
|
q++;
|
||||||
}
|
}
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23389,9 +23389,9 @@ cat >>conftest.$ac_ext <<_ACEOF
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main()
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
{
|
#include <sys/types.h>
|
||||||
char buffer[256];
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SSIZE_T
|
#ifdef HAVE_SSIZE_T
|
||||||
typedef ssize_t Py_ssize_t;
|
typedef ssize_t Py_ssize_t;
|
||||||
|
@ -23401,6 +23401,10 @@ typedef long Py_ssize_t;
|
||||||
typedef int Py_ssize_t;
|
typedef int Py_ssize_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
|
||||||
if(sprintf(buffer, "%zd", (size_t)123) < 0)
|
if(sprintf(buffer, "%zd", (size_t)123) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
10
configure.in
10
configure.in
|
@ -3429,9 +3429,9 @@ AC_TRY_RUN([#include <stdio.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main()
|
#ifdef HAVE_SYS_TYPES_H
|
||||||
{
|
#include <sys/types.h>
|
||||||
char buffer[256];
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SSIZE_T
|
#ifdef HAVE_SSIZE_T
|
||||||
typedef ssize_t Py_ssize_t;
|
typedef ssize_t Py_ssize_t;
|
||||||
|
@ -3441,6 +3441,10 @@ typedef long Py_ssize_t;
|
||||||
typedef int Py_ssize_t;
|
typedef int Py_ssize_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
char buffer[256];
|
||||||
|
|
||||||
if(sprintf(buffer, "%zd", (size_t)123) < 0)
|
if(sprintf(buffer, "%zd", (size_t)123) < 0)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue