Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1cd26f2

Browse files
committed
Add complex().
Update int(), long(), float() to support string conversions.
1 parent 740eb82 commit 1cd26f2

2 files changed

Lines changed: 60 additions & 10 deletions

File tree

Doc/lib/libfuncs.tex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ \section{Built-in Functions}
5757
\code{None} will printed).
5858
\end{funcdesc}
5959

60+
\begin{funcdesc}{complex}{real\optional{, imag}}
61+
Create a complex number with the value \var{real} + \var{imag}*j.
62+
Each argument may be any numeric type (including complex).
63+
If \var{imag} is omitted, it defaults to zero and the function
64+
serves as a numeric conversion function like \code{int}, \code{long}
65+
and \code{float}.
66+
\end{funcdesc}
67+
6068
\begin{funcdesc}{delattr}{object\, name}
6169
This is a relative of \code{setattr}. The arguments are an
6270
object and a string. The string must be the name
@@ -153,8 +161,14 @@ \section{Built-in Functions}
153161
\end{funcdesc}
154162

155163
\begin{funcdesc}{float}{x}
156-
Convert a number to floating point. The argument may be a plain or
157-
long integer or a floating point number.
164+
Convert a string or a number to floating point. If the argument is a
165+
string, it must contain a possibly singed decimal or floating point
166+
number, possibly embedded in whitespace;
167+
this behaves identical to \code{string.atof(\var{x})}.
168+
Otherwise, the argument may be a plain or
169+
long integer or a floating point number, and a floating point number
170+
with the same value (within Python's floating point precision) is
171+
returned.
158172
\end{funcdesc}
159173

160174
\begin{funcdesc}{getattr}{object\, name}
@@ -226,7 +240,11 @@ \section{Built-in Functions}
226240
\end{funcdesc}
227241

228242
\begin{funcdesc}{int}{x}
229-
Convert a number to a plain integer. The argument may be a plain or
243+
Convert a string or number to a plain integer. If the argument is a
244+
string, it must contain a possibly singed decimal number
245+
representable as a Python integer, possibly embedded in whitespace;
246+
this behaves identical to \code{string.atoi(\var{x})}.
247+
Otherwise, the argument may be a plain or
230248
long integer or a floating point number. Conversion of floating
231249
point numbers to integers is defined by the C semantics; normally
232250
the conversion truncates towards zero.\footnote{This is ugly --- the
@@ -245,8 +263,15 @@ \section{Built-in Functions}
245263
\end{funcdesc}
246264

247265
\begin{funcdesc}{long}{x}
248-
Convert a number to a long integer. The argument may be a plain or
249-
long integer or a floating point number.
266+
Convert a string or number to a long integer. If the argument is a
267+
string, it must contain a possibly singed decimal number of
268+
arbitrary size, possibly embedded in whitespace;
269+
this behaves identical to \code{string.atol(\var{x})}.
270+
Otherwise, the argument may be a plain or
271+
long integer or a floating point number, and a long interger with
272+
the same value is returned. Conversion of floating
273+
point numbers to integers is defined by the C semantics;
274+
see the description of \code{int()}.
250275
\end{funcdesc}
251276

252277
\begin{funcdesc}{map}{function\, list\, ...}

Doc/libfuncs.tex

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ \section{Built-in Functions}
5757
\code{None} will printed).
5858
\end{funcdesc}
5959

60+
\begin{funcdesc}{complex}{real\optional{, imag}}
61+
Create a complex number with the value \var{real} + \var{imag}*j.
62+
Each argument may be any numeric type (including complex).
63+
If \var{imag} is omitted, it defaults to zero and the function
64+
serves as a numeric conversion function like \code{int}, \code{long}
65+
and \code{float}.
66+
\end{funcdesc}
67+
6068
\begin{funcdesc}{delattr}{object\, name}
6169
This is a relative of \code{setattr}. The arguments are an
6270
object and a string. The string must be the name
@@ -153,8 +161,14 @@ \section{Built-in Functions}
153161
\end{funcdesc}
154162

155163
\begin{funcdesc}{float}{x}
156-
Convert a number to floating point. The argument may be a plain or
157-
long integer or a floating point number.
164+
Convert a string or a number to floating point. If the argument is a
165+
string, it must contain a possibly singed decimal or floating point
166+
number, possibly embedded in whitespace;
167+
this behaves identical to \code{string.atof(\var{x})}.
168+
Otherwise, the argument may be a plain or
169+
long integer or a floating point number, and a floating point number
170+
with the same value (within Python's floating point precision) is
171+
returned.
158172
\end{funcdesc}
159173

160174
\begin{funcdesc}{getattr}{object\, name}
@@ -226,7 +240,11 @@ \section{Built-in Functions}
226240
\end{funcdesc}
227241

228242
\begin{funcdesc}{int}{x}
229-
Convert a number to a plain integer. The argument may be a plain or
243+
Convert a string or number to a plain integer. If the argument is a
244+
string, it must contain a possibly singed decimal number
245+
representable as a Python integer, possibly embedded in whitespace;
246+
this behaves identical to \code{string.atoi(\var{x})}.
247+
Otherwise, the argument may be a plain or
230248
long integer or a floating point number. Conversion of floating
231249
point numbers to integers is defined by the C semantics; normally
232250
the conversion truncates towards zero.\footnote{This is ugly --- the
@@ -245,8 +263,15 @@ \section{Built-in Functions}
245263
\end{funcdesc}
246264

247265
\begin{funcdesc}{long}{x}
248-
Convert a number to a long integer. The argument may be a plain or
249-
long integer or a floating point number.
266+
Convert a string or number to a long integer. If the argument is a
267+
string, it must contain a possibly singed decimal number of
268+
arbitrary size, possibly embedded in whitespace;
269+
this behaves identical to \code{string.atol(\var{x})}.
270+
Otherwise, the argument may be a plain or
271+
long integer or a floating point number, and a long interger with
272+
the same value is returned. Conversion of floating
273+
point numbers to integers is defined by the C semantics;
274+
see the description of \code{int()}.
250275
\end{funcdesc}
251276

252277
\begin{funcdesc}{map}{function\, list\, ...}

0 commit comments

Comments
 (0)