Commit Graph

67 Commits

Author SHA1 Message Date
Facundo Batista 2ec7415db5 Faster _fix function, and some reordering for a more elegant
coding. Thanks Mark Dickinson.
2007-12-03 17:55:00 +00:00
Facundo Batista 62edb71556 Speedup and cleaning of __str__. Thanks Mark Dickinson. 2007-12-03 16:29:52 +00:00
Facundo Batista 0d157a0154 Reordering of __new__ to minimize isinstance() calls to most
used types. Thanks Mark Dickinson.
2007-11-30 17:15:25 +00:00
Facundo Batista 72bc54faed Major change in the internal structure of the Decimal
number: now it does not store the mantissa as a tuple
of numbers, but as a string.

This avoids a lot of conversions, and achieves a
speedup of 40%. The API remains intact.

Thanks Mark Dickinson.
2007-11-23 17:59:00 +00:00
Facundo Batista 9b5e23148b The constructor from tuple was way too permissive: it allowed bad
coefficient numbers, floats in the sign, and other details that
generated directly the wrong number in the best case, or triggered
misfunctionality in the alorithms.

Test cases added for these issues. Thanks Mark Dickinson.
2007-10-19 19:25:57 +00:00
Facundo Batista be6c7ba72a Added a class to store the digits of log(10), so that they can be made
available when necessary without recomputing.  Thanks Mark Dickinson
2007-10-02 18:21:18 +00:00
Facundo Batista 1a191df14d Made the various is_* operations return booleans. This was discussed
with Cawlishaw by mail, and he basically confirmed that to these is_*
operations, there's no need to return Decimal(0) and Decimal(1) if
the language supports the False and True booleans.

Also added a few tests for the these functions in extra.decTest, since
they are mostly untested (apart from the doctests).

Thanks Mark Dickinson
2007-10-02 17:01:24 +00:00
Facundo Batista 8c20244069 Issue #1772851. Optimization of __hash__ to behave better for big big
numbers.
2007-09-19 17:53:25 +00:00
Facundo Batista cce8df2f67 Speed up of the various division operations (remainder, divide,
divideint and divmod). Thanks Mark Dickinson.
2007-09-18 16:53:18 +00:00
Facundo Batista 6c398da0e7 The methods always return Decimal classes, even if they're
executed through a subclass (thanks Mark Dickinson).
Added a bit of testing for this.
2007-09-17 17:30:13 +00:00
Facundo Batista bd2fe839db Put the parameter watchexp back in (changed watchexp from an int
to a bool).  Also second argument to watchexp is now converted
to Decimal, just as with all the other two-argument operations.

Thanks Mark Dickinson.
2007-09-13 18:42:09 +00:00
Facundo Batista 353750c405 Merged the decimal-branch (revisions 54886 to 58140). Decimal is now
fully updated to the latests Decimal Specification (v1.66) and the
latests test cases (v2.56).

Thanks to Mark Dickinson for all his help during this process.
2007-09-13 18:13:15 +00:00
Facundo Batista 849693989a When passed a bad formed literal to Decimal, now we have a
better error message, more descriptive. (bug #1770009)
2007-08-15 15:13:09 +00:00
Neal Norwitz 0d4c06e06e Whitespace normalization. Ugh, we really need to do this more often.
You might want to review this change as it's my first time.  Be gentle. :-)
2007-04-25 06:30:05 +00:00
Facundo Batista 59c5884b4c General clean-up. Lot of margin corrections, comments, some typos.
Exceptions now are raised in the new style. And a mockup class is
now also new style. Thanks Santiago Pereson.
2007-04-10 12:58:45 +00:00
Raymond Hettinger 495df4716f Fix docstring bug 2007-02-08 01:42:35 +00:00
Neal Norwitz 681d86743c Add missing word in comment 2006-09-02 18:51:34 +00:00
Nick Coghlan ced1218dd1 Make decimal.ContextManager a private implementation detail of decimal.localcontext() 2006-09-02 03:54:17 +00:00
Nick Coghlan 8b6999b4c5 Fix the wrongheaded implementation of context management in the decimal module and add unit tests. (python-dev discussion is ongoing regarding what we do about Python 2.5) 2006-08-31 12:00:43 +00:00
Martin v. Löwis cfe3128cd5 Revert r50706 (Whitespace normalization) and
r50697: Comments and docs cleanups, and some little fixes
per recommendation from Raymond Hettinger.
2006-07-19 17:18:32 +00:00
Tim Peters 73a9eade1c Whitespace normalization. 2006-07-18 21:55:15 +00:00
Facundo Batista ac4ae4baf7 Comments and docs cleanups, and some little fixes, provided by Santiágo Peresón 2006-07-18 12:16:13 +00:00
Georg Brandl 1fb9f528bd Typo fix. 2006-05-11 19:57:09 +00:00
Nick Coghlan afd5e63e24 Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager() 2006-05-03 13:02:47 +00:00
Guido van Rossum da5b701aee Get rid of __context__, per the latest changes to PEP 343 and python-dev
discussion.
There are two places of documentation that still mention __context__:
Doc/lib/libstdtypes.tex -- I wasn't quite sure how to rewrite that without
spending a whole lot of time thinking about it; and whatsnew, which Andrew
usually likes to change himself.
2006-05-02 19:47:52 +00:00
Nick Coghlan a7e820a408 Move the PEP 343 documentation and implementation closer to the
terminology in the alpha 1 documentation.

 - "context manager" reverts to its alpha 1 definition
 - the term "context specifier" goes away entirely
 - contextlib.GeneratorContextManager is renamed GeneratorContext

There are still a number of changes relative to alpha 1:

  - the expression in the with statement is explicitly called the
    "context expression" in the language reference
  - the terms 'with statement context', 'context object' or 'with
    statement context' are used in several places instead of a bare
    'context'. The aim of this is to avoid ambiguity in relation to the
    runtime context set up when the block is executed, and the context
    objects that already exist in various application domains (such as
    decimal.Context)
  - contextlib.contextmanager is renamed to contextfactory
    This best reflects the nature of the function resulting from the
    use of that decorator
  - decimal.ContextManager is renamed to WithStatementContext
    Simple dropping the 'Manager' part wasn't possible due to the
    fact that decimal.Context already exists and means something
    different. WithStatementContext is ugly but workable.

A technically unrelated change snuck into this commit:
contextlib.closing now avoids the overhead of creating a
generator, since it's trivial to implement that particular
context manager directly.
2006-04-25 10:56:51 +00:00
Guido van Rossum f669436189 Um, I thought I'd already checked this in.
Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
2006-03-10 02:28:35 +00:00
Guido van Rossum 1a5e21e033 Updates to the with-statement:
- New semantics for __exit__() -- it must re-raise the exception
  if type is not None; the with-statement itself doesn't do this.
  (See the updated PEP for motivation.)

- Added context managers to:
  - file
  - thread.LockType
  - threading.{Lock,RLock,Condition,Semaphore,BoundedSemaphore}
  - decimal.Context

- Added contextlib.py, which defines @contextmanager, nested(), closing().

- Unit tests all around; bot no docs yet.
2006-02-28 21:57:43 +00:00
Georg Brandl f33d01d304 bug [ 1266296 ] Mistakes in decimal.Context.subtract documentation 2005-08-22 19:35:18 +00:00
Raymond Hettinger e5a0a9609f Apply the _is_special guard. 2005-06-20 09:49:42 +00:00
Raymond Hettinger eb2608415e Minor namespace clean-up. 2005-06-07 18:52:34 +00:00
Raymond Hettinger 267b868f23 * Fix decimal's handling of foreign types. Now returns NotImplemented
instead of raising a TypeError.  Allows other types to successfully
  implement __radd__() style methods.
* Remove future division import from test suite.
* Remove test suite's shadowing of __builtin__.dir().
2005-03-27 10:47:39 +00:00
Raymond Hettinger bea3f6f5c7 Bug #1163325: "special" decimals aren't hashable 2005-03-15 04:59:17 +00:00
Brett Cannon 46b0802ccd Fix small grammatical error in a docstring. 2005-03-01 03:12:26 +00:00
Raymond Hettinger dbecd93b72 Replace list of constants with tuples of constants. 2005-02-06 06:57:08 +00:00
Raymond Hettinger 7e71fa5cfa Bug #1083645
* The decimal module wouldn't load on builds without threads.
2004-12-18 19:07:19 +00:00
Raymond Hettinger 605ed02483 SF bug #1071588 coercing decimal to int doesn't work between -1 and 1 2004-11-24 07:28:48 +00:00
Raymond Hettinger 17931de110 SF patch #1053375.
(Contributed by Facundo Batista.)

Code simplification by eliminating the unnecessary and error-prone
convolutions for the previously weird sign convention in _WorkRep().
Makes the code more understandable, more reliable, and a bit faster.
2004-10-27 06:21:46 +00:00
Facundo Batista 99b5548298 Very few little improvements. 2004-10-26 23:38:46 +00:00
Raymond Hettinger 76e60d687d SF bug #1048728: Bug fixes and cleanup for decimal.py
(Contributed by Neal Norwitz.  Reviewed by Facundo Bastista.)
2004-10-20 06:58:28 +00:00
Raymond Hettinger abf8a56e68 Don't use mutable values for method defaults. 2004-10-12 09:12:16 +00:00
Raymond Hettinger dab988dd23 SF patch #1043218
Simplify internal calls and logic for _fix() and _fixexponents().
(Contributed by Facundo Batista.)
2004-10-09 07:10:44 +00:00
Raymond Hettinger 4837a223ee Use floor division operator. 2004-09-27 14:23:40 +00:00
Raymond Hettinger 636a6b100f SF patch #1020845: Decimal performance enhancements
(Contributed by Nick Coghlan.)

Various code cleanups and optimizations (saves about 40% on testsuite
execution time and on the telco benchmark).

* caches results of various operations on self (esp. checks for being
  a special value).

* _WorkRep now uses ints and longs for intermediate computations.
2004-09-19 01:54:09 +00:00
Raymond Hettinger 27dbcf2162 Establish policies with respect to 2.3 compatibilty and treated spec
updates as bugfixes.
2004-08-19 22:39:55 +00:00
Raymond Hettinger d6c700a320 Revise max() and min() to comply with the 8/2/2004 update to the specification
(version 1.45):

The max and min operations follow the rules in the current IEEE 754 revision draft:
if one operand is a quiet NaN and the other is number, then the number is always returned
if both operands are finite and equal in numerical value then an ordering is applied:
    if the signs differ then max returns the operand with the positive sign and
    min returns the operand with the negative sign; if the signs are the same then
    the exponent is used to select the result.
2004-08-17 06:39:37 +00:00
Raymond Hettinger 9fce44bc8c * Context.copy() now makes a deepcopy.
* Facilitate reloads of local thread.
2004-08-08 04:03:24 +00:00
Raymond Hettinger 61992efc4b SF bug #1002530: test_decimal fails if repeated
* Protect the pre-defined contexts by using a deepcopy() instead of copy().
* Micro-optimization:  prefer x&1 over x%2
2004-08-06 23:42:16 +00:00
Raymond Hettinger ef66debd7e Use threading.local() instead of threading.currentThread(). 2004-07-14 21:04:27 +00:00
Raymond Hettinger 99148e7eaa Factor out two unnecessary global variables. 2004-07-14 19:56:56 +00:00