Mercurial > cpython-lru_cache-weakref
annotate Lib/numbers.py @ 78069:a8aa77458e12 3.2
Add c_size_t and c_ssize_t to the ctypes summary table.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 12 Jul 2012 20:31:50 +0200 |
| parents | 65e5b68b24b1 |
| children | e979b26a9172 |
| rev | line source |
|---|---|
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 # Copyright 2007 Google, Inc. All Rights Reserved. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 # Licensed to PSF under a Contributor Agreement. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
4 """Abstract Base Classes (ABCs) for numbers, according to PEP 3141. |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
5 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
6 TODO: Fill out more detailed documentation on the operators.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 from abc import ABCMeta, abstractmethod, abstractproperty |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 |
|
45774
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
10 __all__ = ["Number", "Complex", "Real", "Rational", "Integral"] |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 class Number(metaclass=ABCMeta): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 """All numbers inherit from this class. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 If you just want to check if an argument x is a number, without |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 caring what kind, use isinstance(x, Number). |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 """ |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
18 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
19 |
|
48740
1a41d456d802
Forward port only Py3k relevant change in r65642 (giving it a Py3k NEWS entry anyway because of the difference in the changes between the two branches)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45774
diff
changeset
|
20 # Concrete numeric types must provide their own hash implementation |
|
1a41d456d802
Forward port only Py3k relevant change in r65642 (giving it a Py3k NEWS entry anyway because of the difference in the changes between the two branches)
Nick Coghlan <ncoghlan@gmail.com>
parents:
45774
diff
changeset
|
21 __hash__ = None |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
45333
e70f56cf6972
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45307
diff
changeset
|
24 ## Notes on Decimal |
|
e70f56cf6972
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45307
diff
changeset
|
25 ## ---------------- |
|
e70f56cf6972
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45307
diff
changeset
|
26 ## Decimal has all of the methods specified by the Real abc, but it should |
|
e70f56cf6972
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60766,60769-60786 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45307
diff
changeset
|
27 ## not be registered as a Real because decimals do not interoperate with |
|
45774
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
28 ## binary floats (i.e. Decimal('3.14') + 2.71828 is undefined). But, |
|
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
29 ## abstract reals are expected to interoperate (i.e. R1 + R2 should be |
|
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
30 ## expected to work if R1 and R2 are both Reals). |
|
45307
f1205121e848
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60735-60751 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45244
diff
changeset
|
31 |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 class Complex(Number): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 """Complex defines the operations that work on the builtin complex type. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 In short, those are: a conversion to complex, .real, .imag, +, -, |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 *, /, abs(), .conjugate, ==, and !=. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 If it is given heterogenous arguments, and doesn't have special |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 knowledge about them, it should fall back to the builtin complex |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 type as described below. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
43 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
44 |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 def __complex__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
47 """Return a builtin complex instance. Called for complex(self).""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
44718
26b61a5df11b
Update the py3k version of the rational module to expose only methods needed by
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44699
diff
changeset
|
49 def __bool__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
50 """True if self != 0. Called for bool(self).""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 return self != 0 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 @abstractproperty |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 def real(self): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 """Retrieve the real component of this number. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 This should subclass Real. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 @abstractproperty |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 def imag(self): |
|
67102
c34ac9f9de83
Merged revisions 87455 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51567
diff
changeset
|
63 """Retrieve the imaginary component of this number. |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 This should subclass Real. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 def __add__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
71 """self + other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
74 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 def __radd__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
76 """other + self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
79 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 def __neg__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
81 """-self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
84 @abstractmethod |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 def __pos__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
86 """+self""" |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
87 raise NotImplementedError |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
88 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 def __sub__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
90 """self - other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 return self + -other |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 def __rsub__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
94 """other - self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 return -self + other |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 def __mul__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
99 """self * other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 def __rmul__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
104 """other * self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 @abstractmethod |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
108 def __truediv__(self, other): |
|
44718
26b61a5df11b
Update the py3k version of the rational module to expose only methods needed by
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44699
diff
changeset
|
109 """self / other: Should promote to float when necessary.""" |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
110 raise NotImplementedError |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
111 |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
112 @abstractmethod |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
113 def __rtruediv__(self, other): |
|
44718
26b61a5df11b
Update the py3k version of the rational module to expose only methods needed by
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
44699
diff
changeset
|
114 """other / self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 def __pow__(self, exponent): |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
119 """self**exponent; should promote to float or complex when necessary.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 def __rpow__(self, base): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
124 """base ** self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 def __abs__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
129 """Returns the Real distance from 0. Called for abs(self).""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 def conjugate(self): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 """(x+y*i).conjugate() returns (x-y*i).""" |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 def __eq__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
139 """self == other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
45244
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45071
diff
changeset
|
142 def __ne__(self, other): |
|
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45071
diff
changeset
|
143 """self != other""" |
|
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45071
diff
changeset
|
144 # The default __ne__ doesn't negate __eq__ until 3.0. |
|
2a821e001a2b
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617-60678 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45071
diff
changeset
|
145 return not (self == other) |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 Complex.register(complex) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 class Real(Complex): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 """To Complex, Real adds the operations that work on real numbers. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 In short, those are: a conversion to float, trunc(), divmod, |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 %, <, <=, >, and >=. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 Real also provides defaults for the derived operations. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
159 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
160 |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 def __float__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
163 """Any Real can be converted to a native float object. |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
164 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
165 Called for float(self).""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 def __trunc__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
170 """trunc(self): Truncates self to an Integral. |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 Returns an Integral i such that: |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
173 * i>0 iff self>0; |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
174 * abs(i) <= abs(self); |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
175 * for any Integral j satisfying the first two conditions, |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
176 abs(i) >= abs(j) [i.e. i has "maximal" abs among those]. |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
177 i.e. "truncate towards 0". |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
178 """ |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
179 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
180 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
181 @abstractmethod |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
182 def __floor__(self): |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
183 """Finds the greatest Integral <= self.""" |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
184 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
185 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
186 @abstractmethod |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
187 def __ceil__(self): |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
188 """Finds the least Integral >= self.""" |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
189 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
190 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
191 @abstractmethod |
|
67565
4abfb7670ead
Remove the funky function annotation from numbers.py.
Raymond Hettinger <python@rcn.com>
parents:
67102
diff
changeset
|
192 def __round__(self, ndigits=None): |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
193 """Rounds self to ndigits decimal places, defaulting to 0. |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
194 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
195 If ndigits is omitted or None, returns an Integral, otherwise |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
196 returns a Real. Rounds half toward even. |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 def __divmod__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
201 """divmod(self, other): The pair (self // other, self % other). |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 Sometimes this can be computed faster than the pair of |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 operations. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 return (self // other, self % other) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 def __rdivmod__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
209 """divmod(other, self): The pair (self // other, self % other). |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 Sometimes this can be computed faster than the pair of |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 operations. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 return (other // self, other % self) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 def __floordiv__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
218 """self // other: The floor() of self/other.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 def __rfloordiv__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
223 """other // self: The floor() of other/self.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
225 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
227 def __mod__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
228 """self % other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
229 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
231 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 def __rmod__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
233 """other % self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
236 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
237 def __lt__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
238 """self < other |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
239 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
240 < on Reals defines a total ordering, except perhaps for NaN.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
241 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
243 @abstractmethod |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 def __le__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
245 """self <= other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 # Concrete implementations of Complex abstract methods. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 def __complex__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
250 """complex(self) == complex(float(self), 0)""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 return complex(float(self)) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 @property |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 def real(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
255 """Real numbers are their real component.""" |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
256 return +self |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 @property |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 def imag(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
260 """Real numbers have no imaginary component.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 return 0 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 def conjugate(self): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 """Conjugate is a no-op for Reals.""" |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
265 return +self |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 Real.register(float) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 |
|
45774
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
270 class Rational(Real): |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
271 """.numerator and .denominator should be in lowest terms.""" |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
272 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
273 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
274 |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
275 @abstractproperty |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
276 def numerator(self): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
277 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
278 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
279 @abstractproperty |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
280 def denominator(self): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
281 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
282 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
283 # Concrete implementation of Real's conversion to float. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
284 def __float__(self): |
|
45071
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
285 """float(self) = self.numerator / self.denominator |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
286 |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
287 It's important that this conversion use the integer's "true" |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
288 division rather than casting one side to float before dividing |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
289 so that ratios of huge integers convert without overflowing. |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
290 |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
291 """ |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
292 return self.numerator / self.denominator |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
293 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
294 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 class Integral(Rational): |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
296 """Integral adds a conversion to int and the bit-string operations.""" |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
298 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
299 |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
300 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
301 def __int__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
302 """int(self)""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
303 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
304 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
305 def __index__(self): |
|
73327
65e5b68b24b1
Fix incorrect docstring I changed a while back.
Éric Araujo <merwok@netwok.org>
parents:
68257
diff
changeset
|
306 """Called whenever an index is needed, such as in slicing""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
307 return int(self) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
308 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
309 @abstractmethod |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
310 def __pow__(self, exponent, modulus=None): |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
311 """self ** exponent % modulus, but maybe faster. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
312 |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
313 Accept the modulus argument if you want to support the |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
314 3-argument version of pow(). Raise a TypeError if exponent < 0 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
315 or any argument isn't Integral. Otherwise, just implement the |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
316 2-argument version described in Complex. |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
317 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
318 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
319 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
320 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
321 def __lshift__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
322 """self << other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
323 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
324 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
325 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
326 def __rlshift__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
327 """other << self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
328 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
329 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
330 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
331 def __rshift__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
332 """self >> other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
333 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
334 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
335 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
336 def __rrshift__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
337 """other >> self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
338 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
339 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
340 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
341 def __and__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
342 """self & other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
343 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
344 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
346 def __rand__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
347 """other & self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
348 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 def __xor__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
352 """self ^ other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
353 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
356 def __rxor__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
357 """other ^ self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
358 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
359 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
360 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
361 def __or__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
362 """self | other""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
363 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
364 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
365 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
366 def __ror__(self, other): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
367 """other | self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
368 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
369 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
370 @abstractmethod |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
371 def __invert__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
372 """~self""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
373 raise NotImplementedError |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
374 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
375 # Concrete implementations of Rational and Real abstract methods. |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 def __float__(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
377 """float(self) == float(int(self))""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 return float(int(self)) |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 @property |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 def numerator(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
382 """Integers are their own numerators.""" |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
383 return +self |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 @property |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 def denominator(self): |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
387 """Integers have a denominator of 1.""" |
|
43063
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 return 1 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 Integral.register(int) |
