Mercurial > cpython-lru_cache-weakref
annotate Lib/numbers.py @ 79691:05c8928362ee
Merge __next__ method link fixes with 3.3.
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Fri, 12 Oct 2012 13:46:37 +0300 |
| parents | e979b26a9172 |
| children |
| 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 |
|
73984
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
8 from abc import ABCMeta, 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
|
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 |
|
73984
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
53 @property |
|
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
54 @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
|
55 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
|
56 """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
|
57 |
|
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 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
|
59 """ |
|
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 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
|
61 |
|
73984
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
62 @property |
|
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
63 @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
|
64 def imag(self): |
|
67102
c34ac9f9de83
Merged revisions 87455 via svnmerge from
Benjamin Peterson <benjamin@python.org>
parents:
51567
diff
changeset
|
65 """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
|
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 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
|
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 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
|
70 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 @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
|
72 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
|
73 """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
|
74 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
|
75 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 @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
|
77 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
|
78 """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
|
79 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
|
80 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 @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
|
82 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
|
83 """-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
|
84 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
|
85 |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
86 @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
|
87 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
|
88 """+self""" |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
89 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
|
90 |
|
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 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
|
92 """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
|
93 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
|
94 |
|
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 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
|
96 """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
|
97 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
|
98 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 @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
|
100 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
|
101 """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
|
102 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
|
103 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 @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
|
105 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
|
106 """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
|
107 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
|
108 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 @abstractmethod |
|
44699
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
110 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
|
111 """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
|
112 raise NotImplementedError |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
113 |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
114 @abstractmethod |
|
6f049ca55e06
Merged revisions 59952-59984 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
44202
diff
changeset
|
115 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
|
116 """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
|
117 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
|
118 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 @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
|
120 def __pow__(self, exponent): |
|
44202
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
121 """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
|
122 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
|
123 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 @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
|
125 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
|
126 """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
|
127 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
|
128 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 @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
|
130 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
|
131 """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
|
132 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
|
133 |
|
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 @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
|
135 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
|
136 """(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
|
137 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
|
138 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 @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
|
140 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
|
141 """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
|
142 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
|
143 |
|
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
|
144 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
|
145 """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
|
146 # 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
|
147 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
|
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 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
|
150 |
|
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 |
|
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 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
|
153 """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
|
154 |
|
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 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
|
156 %, <, <=, >, 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
|
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 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
|
159 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
161 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
162 |
|
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
|
163 @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
|
164 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
|
165 """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
|
166 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
167 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
|
168 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
|
169 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 @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
|
171 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
|
172 """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
|
173 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 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
|
175 * i>0 iff self>0; |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
176 * abs(i) <= abs(self); |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
177 * 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
|
178 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
|
179 i.e. "truncate towards 0". |
|
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 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
182 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
183 @abstractmethod |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
184 def __floor__(self): |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
185 """Finds the greatest Integral <= self.""" |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
186 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
187 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
188 @abstractmethod |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
189 def __ceil__(self): |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
190 """Finds the least Integral >= self.""" |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
191 raise NotImplementedError |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
192 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
193 @abstractmethod |
|
67565
4abfb7670ead
Remove the funky function annotation from numbers.py.
Raymond Hettinger <python@rcn.com>
parents:
67102
diff
changeset
|
194 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
|
195 """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
|
196 |
|
71ad5e2bedda
Small set of updates (with Jeffrey's OK).
Guido van Rossum <guido@python.org>
parents:
43284
diff
changeset
|
197 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
|
198 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
|
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 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
|
201 |
|
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 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
|
203 """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
|
204 |
|
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 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
|
206 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
|
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 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
|
209 |
|
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 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
|
211 """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
|
212 |
|
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 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
|
214 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
|
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 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
|
217 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 @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
|
219 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
|
220 """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
|
221 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
|
222 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 @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
|
224 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
|
225 """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
|
226 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
|
227 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 @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
|
229 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
|
230 """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
|
231 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
|
232 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
233 @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
|
234 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
|
235 """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
|
236 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
|
237 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
238 @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
|
239 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
|
240 """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
|
241 |
|
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
242 < 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
|
243 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
|
244 |
|
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 @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
|
246 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
|
247 """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
|
248 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
|
249 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 # 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
|
251 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
|
252 """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
|
253 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
|
254 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 @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
|
256 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
|
257 """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
|
258 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
|
259 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 @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
|
261 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
|
262 """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
|
263 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
|
264 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 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
|
266 """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
|
267 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
|
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 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
|
270 |
|
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 |
|
45774
058fbfb985ae
Merged revisions 61404-61407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45333
diff
changeset
|
272 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
|
273 """.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
|
274 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
275 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
276 |
|
73984
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
277 @property |
|
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
278 @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
|
279 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
|
280 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
|
281 |
|
73984
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
282 @property |
|
e979b26a9172
improve abstract property support (closes #11610)
Benjamin Peterson <benjamin@python.org>
parents:
73327
diff
changeset
|
283 @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
|
284 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
|
285 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
|
286 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
287 # 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
|
288 def __float__(self): |
|
45071
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
289 """float(self) = self.numerator / self.denominator |
|
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 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
|
292 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
|
293 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
|
294 |
|
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44718
diff
changeset
|
295 """ |
|
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
|
296 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
|
297 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
298 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
299 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
|
300 """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
|
301 |
|
51567
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
302 __slots__ = () |
|
5d28405080ed
Merged revisions 69547 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
48740
diff
changeset
|
303 |
|
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
|
304 @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
|
305 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
|
306 """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
|
307 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
|
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 def __index__(self): |
|
73327
65e5b68b24b1
Fix incorrect docstring I changed a while back.
Éric Araujo <merwok@netwok.org>
parents:
68257
diff
changeset
|
310 """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
|
311 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
|
312 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
313 @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
|
314 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
|
315 """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
|
316 |
|
43284
1f9eee08ab35
Check in some documentation tweaks for PEP 3141, add some tests, and implement
Jeffrey Yasskin <jyasskin@gmail.com>
parents:
43063
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 """ |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
322 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
|
323 |
|
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 @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
|
325 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
|
326 """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
|
327 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
|
328 |
|
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 @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
|
330 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
|
331 """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
|
332 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
|
333 |
|
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 @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
|
335 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
|
336 """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
|
337 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
|
338 |
|
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 @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
|
340 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
|
341 """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
|
342 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
|
343 |
|
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 @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
|
345 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
|
346 """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
|
347 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
|
348 |
|
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 @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
|
350 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
|
351 """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
|
352 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
|
353 |
|
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 @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
|
355 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
|
356 """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
|
357 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
|
358 |
|
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 @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
|
360 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
|
361 """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
|
362 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
|
363 |
|
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 @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
|
365 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
|
366 """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
|
367 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
|
368 |
|
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 @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
|
370 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
|
371 """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
|
372 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
|
373 |
|
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 @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
|
375 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
|
376 """~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
|
377 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
|
378 |
|
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 # 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
|
380 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
|
381 """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
|
382 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
|
383 |
|
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 @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
|
385 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
|
386 """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
|
387 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
|
388 |
|
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 @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
|
390 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
|
391 """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
|
392 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
|
393 |
|
e7a390a36ec8
Add numbers.py. I suspect this is an old version, but Jeffrey is out
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
394 Integral.register(int) |
