Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
86e01ff9
Commit
86e01ff9
authored
Jan 31, 2008
by
Jeffrey Yasskin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused to-be-magic methods from Rational per issue 1968. Do not port
this patch to py3k.
parent
71d8f148
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
49 deletions
+0
-49
Lib/rational.py
Lib/rational.py
+0
-34
Lib/test/test_rational.py
Lib/test/test_rational.py
+0
-15
No files found.
Lib/rational.py
View file @
86e01ff9
...
...
@@ -410,40 +410,6 @@ class Rational(RationalAbc):
__int__
=
__trunc__
def
__floor__
(
a
):
"""Will be math.floor(a) in 3.0."""
return
a
.
numerator
//
a
.
denominator
def
__ceil__
(
a
):
"""Will be math.ceil(a) in 3.0."""
# The negations cleverly convince floordiv to return the ceiling.
return
-
(
-
a
.
numerator
//
a
.
denominator
)
def
__round__
(
self
,
ndigits
=
None
):
"""Will be round(self, ndigits) in 3.0.
Rounds half toward even.
"""
if
ndigits
is
None
:
floor
,
remainder
=
divmod
(
self
.
numerator
,
self
.
denominator
)
if
remainder
*
2
<
self
.
denominator
:
return
floor
elif
remainder
*
2
>
self
.
denominator
:
return
floor
+
1
# Deal with the half case:
elif
floor
%
2
==
0
:
return
floor
else
:
return
floor
+
1
shift
=
10
**
abs
(
ndigits
)
# See _operator_fallbacks.forward to check that the results of
# these operations will always be Rational and therefore have
# __round__().
if
ndigits
>
0
:
return
Rational
((
self
*
shift
).
__round__
(),
shift
)
else
:
return
Rational
((
self
/
shift
).
__round__
()
*
shift
)
def
__hash__
(
self
):
"""hash(self)
...
...
Lib/test/test_rational.py
View file @
86e01ff9
...
...
@@ -197,14 +197,6 @@ class RationalTest(unittest.TestCase):
def
testConversions
(
self
):
self
.
assertTypedEquals
(
-
1
,
trunc
(
R
(
-
11
,
10
)))
self
.
assertTypedEquals
(
-
1
,
int
(
R
(
-
11
,
10
)))
self
.
assertTypedEquals
(
-
2
,
R
(
-
11
,
10
).
__floor__
())
self
.
assertTypedEquals
(
-
1
,
R
(
-
11
,
10
).
__ceil__
())
self
.
assertTypedEquals
(
-
1
,
R
(
-
10
,
10
).
__ceil__
())
self
.
assertTypedEquals
(
0
,
R
(
-
1
,
10
).
__round__
())
self
.
assertTypedEquals
(
0
,
R
(
-
5
,
10
).
__round__
())
self
.
assertTypedEquals
(
-
2
,
R
(
-
15
,
10
).
__round__
())
self
.
assertTypedEquals
(
-
1
,
R
(
-
7
,
10
).
__round__
())
self
.
assertEquals
(
False
,
bool
(
R
(
0
,
1
)))
self
.
assertEquals
(
True
,
bool
(
R
(
3
,
2
)))
...
...
@@ -218,13 +210,6 @@ class RationalTest(unittest.TestCase):
self
.
assertTypedEquals
(
0.1
+
0j
,
complex
(
R
(
1
,
10
)))
def
testRound
(
self
):
self
.
assertTypedEquals
(
R
(
-
200
),
R
(
-
150
).
__round__
(
-
2
))
self
.
assertTypedEquals
(
R
(
-
200
),
R
(
-
250
).
__round__
(
-
2
))
self
.
assertTypedEquals
(
R
(
30
),
R
(
26
).
__round__
(
-
1
))
self
.
assertTypedEquals
(
R
(
-
2
,
10
),
R
(
-
15
,
100
).
__round__
(
1
))
self
.
assertTypedEquals
(
R
(
-
2
,
10
),
R
(
-
25
,
100
).
__round__
(
1
))
def
testArithmetic
(
self
):
self
.
assertEquals
(
R
(
1
,
2
),
R
(
1
,
10
)
+
R
(
2
,
5
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment