Commit Graph

78 Commits

Author SHA1 Message Date
Raymond Hettinger 116f72fa5c Bring decimal a bit closer to the spec for Reals. 2008-02-12 01:18:03 +00:00
Mark Dickinson 3a94ee05f7 Typos in decimal comment and documentation 2008-02-10 15:19:58 +00:00
Mark Dickinson 2fc9263df5 Issue 1979: Make Decimal comparisons (other than !=, ==) involving NaN
raise InvalidOperation (and return False if InvalidOperation is trapped).
2008-02-06 22:10:50 +00:00
Raymond Hettinger 5a05364049 Add support for trunc(). 2008-01-24 19:05:29 +00:00
Andrew M. Kuchling c8acc882a9 Docstring typos 2008-01-16 00:32:03 +00:00
Mark Dickinson 59bc20bb27 Issue 1780: Allow leading and trailing whitespace in Decimal constructor,
when constructing from a string. Disallow trailing newlines in
Context.create_decimal.
2008-01-12 01:56:00 +00:00
Raymond Hettinger 097a190303 Have Decimal.as_tuple return a named tuple. 2008-01-11 02:24:13 +00:00
Facundo Batista 52b25795c0 Issue #1757: The hash of a Decimal instance is no longer affected
by the current context.  Thanks Mark Dickinson.
2008-01-08 12:25:20 +00:00
Facundo Batista 0f5e7bf304 Some minor cleanups. Thanks Mark Dickinson. 2007-12-19 12:53:01 +00:00
Facundo Batista e64acfad3d Removed the private _rounding_decision: it was not needed, and the code
is now simpler.  Thanks Mark Dickinson.
2007-12-17 14:18:42 +00:00
Facundo Batista 58f6f2e0c9 fma speedup by avoiding to create a Context. Thanks Mark Dickinson. 2007-12-04 16:31:53 +00:00
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