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
97fe9c14
Commit
97fe9c14
authored
Aug 14, 2001
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add information about __floordiv__() and __truediv__() methods for
implementing numeric objects in Python.
parent
17a42fb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
Doc/ref/ref3.tex
Doc/ref/ref3.tex
+17
-5
No files found.
Doc/ref/ref3.tex
View file @
97fe9c14
...
...
@@ -1330,7 +1330,7 @@ non-integral numbers) should be left undefined.
\begin{methoddesc}
[numeric object]
{__
add
__}{
self, other
}
\methodline
[numeric object]
{__
sub
__}{
self, other
}
\methodline
[numeric object]
{__
mul
__}{
self, other
}
\methodline
[numeric object]
{__
div
__}{
self, other
}
\methodline
[numeric object]
{__
floor
div
__}{
self, other
}
\methodline
[numeric object]
{__
mod
__}{
self, other
}
\methodline
[numeric object]
{__
divmod
__}{
self, other
}
\methodline
[numeric object]
{__
pow
__}{
self, other
\optional
{
, modulo
}}
...
...
@@ -1339,20 +1339,32 @@ non-integral numbers) should be left undefined.
\methodline
[numeric object]
{__
and
__}{
self, other
}
\methodline
[numeric object]
{__
xor
__}{
self, other
}
\methodline
[numeric object]
{__
or
__}{
self, other
}
These
function
s are
These
method
s are
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
/
}
,
\code
{
\%
}
,
\function
{
divmod()
}
\bifuncindex
{
divmod
}
,
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<
}
\code
{
<
}
,
\code
{
>
}
\code
{
>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
). For instance, to
evaluate the expression
\var
{
x
}
\code
{
+
}
\var
{
y
}
, where
\var
{
x
}
is an
instance of a class that has an
\method
{__
add
__
()
}
method,
\code
{
\var
{
x
}
.
__
add
__
(
\var
{
y
}
)
}
is called. Note that
\code
{
\var
{
x
}
.
__
add
__
(
\var
{
y
}
)
}
is called. The
\method
{__
divmod
__
()
}
method should be the equivalent to using
\method
{__
floordiv
__
()
}
and
\method
{__
mod
__
()
}
; it should not be related to
\method
{__
truediv
__
()
}
(described below). Note that
\method
{__
pow
__
()
}
should be defined to accept an optional third
argument if the ternary version of the built-in
\function
{
pow()
}
\bifuncindex
{
pow
}
function is to be supported.
\end{methoddesc}
\begin{methoddesc}
[numeric object]
{__
div
__}{
self, other
}
\methodline
[numeric object]
{__
truediv
__}{
self, other
}
The division operator (
\code
{
/
}
) is implemented by these methods. The
\method
{__
truediv
__
()
}
method is used when
\code
{__
future
__
.division
}
is in effect, otherwise
\method
{__
div
__
()
}
is used. If only one of
these two methods is defined, the object will not support division in
the alternate context;
\exception
{
TypeError
}
will be raised instead.
\end{methoddesc}
\begin{methoddesc}
[numeric object]
{__
radd
__}{
self, other
}
\methodline
[numeric object]
{__
rsub
__}{
self, other
}
\methodline
[numeric object]
{__
rmul
__}{
self, other
}
...
...
@@ -1365,7 +1377,7 @@ argument if the ternary version of the built-in
\methodline
[numeric object]
{__
rand
__}{
self, other
}
\methodline
[numeric object]
{__
rxor
__}{
self, other
}
\methodline
[numeric object]
{__
ror
__}{
self, other
}
These
function
s are
These
method
s are
called to implement the binary arithmetic operations (
\code
{
+
}
,
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\function
{
divmod()
}
\bifuncindex
{
divmod
}
,
...
...
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