Commit Graph

30 Commits

Author SHA1 Message Date
Jeffrey Yasskin d7b00334f3 Add rational.Rational as an implementation of numbers.Rational with infinite
precision. This has been discussed at http://bugs.python.org/issue1682. It's
useful primarily for teaching, but it also demonstrates how to implement a
member of the numeric tower, including fallbacks for mixed-mode arithmetic.

I expect to write a couple more patches in this area:
 * Rational.from_decimal()
 * Rational.trim/approximate() (maybe with different names)
 * Maybe remove the parentheses from Rational.__str__()
 * Maybe rename one of the Rational classes
 * Maybe make Rational('3/2') work.
2008-01-15 07:46:24 +00:00
Martin Blais 215f13dd11 Normalized a few cases of whitespace in function declarations.
Found them using::

  find . -name '*.py' | while read i ; do grep 'def[^(]*( ' $i /dev/null ; done
  find . -name '*.py' | while read i ; do grep ' ):' $i /dev/null ; done

(I was doing this all over my own code anyway, because I'd been using spaces in
all defs, so I thought I'd make a run on the Python code as well.  If you need
to do such fixes in your own code, you can use xx-rename or parenregu.el within
emacs.)
2006-06-06 12:46:55 +00:00
Raymond Hettinger bdaad8c939 * Fix error in definition of Im() which returned self instead of 0
for non-complex arguments.

* Replace type() comparisons with isinstance() checks.

* Replace apply() calls with equivalent syntactic form.

* Simplify __hash__ definition to hash the underlying tuple.

* Use math.hypot() for more robust computation of __abs__().

* Use sorted() instead of the multi-step keys/sort/iter.

* Update comment on the cmath module.
2005-04-09 14:55:07 +00:00
Martin v. Löwis 4a1e48c566 Patch #1177597: Correct various bugs, add comments. 2005-04-09 10:51:19 +00:00
Brett Cannon c2b151c66e Add code for a range function that uses generators.
Cleaned up existing code by abstracting code to parse arguments.  Also removed
any unneeded operations (such as calling 'int' on a division when using floor
division also works).  Fixed a bug where the values  returned by
OldStyleRange could be short by one value.  Added more documentation.

Testing code also has a basic sanity check.
2004-06-27 23:17:35 +00:00
Walter Dörwald 70a6b49821 Replace backticks with repr() or "%r"
From SF patch #852334.
2004-02-12 17:35:32 +00:00
Raymond Hettinger fe63faaeeb SF patch #803449: modernize demo scripts
(Contributed by George Yoshida.)
2003-09-10 21:12:59 +00:00
Martin v. Löwis 7890c26508 Patch #748846: Let Demo/classes/Date.py mention DateTime module. 2003-06-07 19:39:56 +00:00
Andrew M. Kuchling 946c53ed7f Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged. 2003-04-24 17:13:18 +00:00
Andrew M. Kuchling 4f237b6870 Modernize code by using isinstance() instead of type() checks 2003-04-24 17:04:45 +00:00
Andrew M. Kuchling 64b3c830d4 Avoid TypeError by not comparing complex numbers 2003-04-24 16:59:45 +00:00
Guido van Rossum ecbb0eaa43 Update docs. Remove old classes.doc. 2002-10-18 15:40:13 +00:00
Guido van Rossum eda80eae36 Correct spelling of length, discovered by Christian Tismer. 1999-04-21 16:06:27 +00:00
Guido van Rossum dcd038ff84 nannified. 1998-09-14 15:34:45 +00:00
Guido van Rossum 7ca9a1a466 Fix a bug where comparison of a rational with a float failed because
the difference got converted to float.
Put brackets around the string representation of (non-integer)
rationals.
(Sjoerd Mullender.)
1998-09-09 14:07:06 +00:00
Guido van Rossum 1a24bb53d5 Fix the test for pow() -- no more TypeErrors are raised! 1997-12-09 19:38:39 +00:00
Guido van Rossum 0609f191bc A completely new Rat.py by Sjoerd. 1997-05-13 19:25:57 +00:00
Guido van Rossum 72ba616066 Added note about Python's support of complex numbers.
Added exp(z).
1996-07-30 19:02:01 +00:00
Guido van Rossum 2e61103c0b adapted to new overloading scheme 1994-10-09 22:36:28 +00:00
Guido van Rossum 81a12bceb6 totally redone for new overloading scheme 1994-10-08 18:56:41 +00:00
Guido van Rossum e69d3fec87 Use time.time() instead of time.millitimer() 1994-02-17 12:36:58 +00:00
Guido van Rossum 62326f2108 builtin -> __builtin__ 1994-01-26 16:04:38 +00:00
Guido van Rossum 7565b93414 *** empty log message *** 1993-12-17 14:23:52 +00:00
Guido van Rossum 0a2fa75a9c Added Dates.py and Rev.py 1993-10-30 12:39:49 +00:00
Guido van Rossum 102ababef9 Initial revision 1993-10-30 12:38:16 +00:00
Guido van Rossum becec31f17 Fix bug and use __init__ 1993-10-30 12:38:16 +00:00
Guido van Rossum ed49c5e3f8 *** empty log message *** 1993-10-27 09:29:01 +00:00
Guido van Rossum f1bbf9c308 Add coercions 1993-10-27 09:28:23 +00:00
Guido van Rossum b6957e434f Initial revision 1993-10-27 09:27:13 +00:00
Guido van Rossum e876949f2b Initial revision 1992-08-13 12:14:11 +00:00