blob: 0e70fe5d8c44044f800416832f848405b42702b6 [file] [log] [blame]
Serhiy Storchaka495e8802017-02-01 23:12:20 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
Serhiy Storchaka18b250f2017-03-19 08:51:07 +02005static PyObject *
6long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
7
8static PyObject *
9long_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
10{
11 PyObject *return_value = NULL;
12 static const char * const _keywords[] = {"", "base", NULL};
13 static _PyArg_Parser _parser = {"|OO:int", _keywords, 0};
14 PyObject *x = NULL;
15 PyObject *obase = NULL;
16
17 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
18 &x, &obase)) {
19 goto exit;
20 }
21 return_value = long_new_impl(type, x, obase);
22
23exit:
24 return return_value;
25}
26
Serhiy Storchaka495e8802017-02-01 23:12:20 +020027PyDoc_STRVAR(int___getnewargs____doc__,
28"__getnewargs__($self, /)\n"
29"--\n"
30"\n");
31
32#define INT___GETNEWARGS___METHODDEF \
33 {"__getnewargs__", (PyCFunction)int___getnewargs__, METH_NOARGS, int___getnewargs____doc__},
34
35static PyObject *
36int___getnewargs___impl(PyObject *self);
37
38static PyObject *
39int___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
40{
41 return int___getnewargs___impl(self);
42}
43
44PyDoc_STRVAR(int___format____doc__,
45"__format__($self, format_spec, /)\n"
46"--\n"
47"\n");
48
49#define INT___FORMAT___METHODDEF \
50 {"__format__", (PyCFunction)int___format__, METH_O, int___format____doc__},
51
52static PyObject *
53int___format___impl(PyObject *self, PyObject *format_spec);
54
55static PyObject *
56int___format__(PyObject *self, PyObject *arg)
57{
58 PyObject *return_value = NULL;
59 PyObject *format_spec;
60
61 if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
62 goto exit;
63 }
64 return_value = int___format___impl(self, format_spec);
65
66exit:
67 return return_value;
68}
69
70PyDoc_STRVAR(int___sizeof____doc__,
71"__sizeof__($self, /)\n"
72"--\n"
73"\n"
74"Returns size in memory, in bytes.");
75
76#define INT___SIZEOF___METHODDEF \
77 {"__sizeof__", (PyCFunction)int___sizeof__, METH_NOARGS, int___sizeof____doc__},
78
79static Py_ssize_t
80int___sizeof___impl(PyObject *self);
81
82static PyObject *
83int___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
84{
85 PyObject *return_value = NULL;
86 Py_ssize_t _return_value;
87
88 _return_value = int___sizeof___impl(self);
89 if ((_return_value == -1) && PyErr_Occurred()) {
90 goto exit;
91 }
92 return_value = PyLong_FromSsize_t(_return_value);
93
94exit:
95 return return_value;
96}
97
98PyDoc_STRVAR(int_bit_length__doc__,
99"bit_length($self, /)\n"
100"--\n"
101"\n"
102"Number of bits necessary to represent self in binary.\n"
103"\n"
104">>> bin(37)\n"
105"\'0b100101\'\n"
106">>> (37).bit_length()\n"
107"6");
108
109#define INT_BIT_LENGTH_METHODDEF \
110 {"bit_length", (PyCFunction)int_bit_length, METH_NOARGS, int_bit_length__doc__},
111
112static PyObject *
113int_bit_length_impl(PyObject *self);
114
115static PyObject *
116int_bit_length(PyObject *self, PyObject *Py_UNUSED(ignored))
117{
118 return int_bit_length_impl(self);
119}
120
Lisa Roach5ac70432018-09-13 23:56:23 -0700121PyDoc_STRVAR(int_as_integer_ratio__doc__,
122"as_integer_ratio($self, /)\n"
123"--\n"
124"\n"
125"Return integer ratio.\n"
126"\n"
127"Return a pair of integers, whose ratio is exactly equal to the original int\n"
128"and with a positive denominator.\n"
129"\n"
130">>> (10).as_integer_ratio()\n"
131"(10, 1)\n"
132">>> (-10).as_integer_ratio()\n"
133"(-10, 1)\n"
134">>> (0).as_integer_ratio()\n"
135"(0, 1)");
136
137#define INT_AS_INTEGER_RATIO_METHODDEF \
138 {"as_integer_ratio", (PyCFunction)int_as_integer_ratio, METH_NOARGS, int_as_integer_ratio__doc__},
139
140static PyObject *
141int_as_integer_ratio_impl(PyObject *self);
142
143static PyObject *
144int_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
145{
146 return int_as_integer_ratio_impl(self);
147}
148
Serhiy Storchaka495e8802017-02-01 23:12:20 +0200149PyDoc_STRVAR(int_to_bytes__doc__,
150"to_bytes($self, /, length, byteorder, *, signed=False)\n"
151"--\n"
152"\n"
153"Return an array of bytes representing an integer.\n"
154"\n"
155" length\n"
156" Length of bytes object to use. An OverflowError is raised if the\n"
157" integer is not representable with the given number of bytes.\n"
158" byteorder\n"
159" The byte order used to represent the integer. If byteorder is \'big\',\n"
160" the most significant byte is at the beginning of the byte array. If\n"
161" byteorder is \'little\', the most significant byte is at the end of the\n"
162" byte array. To request the native byte order of the host system, use\n"
163" `sys.byteorder\' as the byte order value.\n"
164" signed\n"
165" Determines whether two\'s complement is used to represent the integer.\n"
166" If signed is False and a negative integer is given, an OverflowError\n"
167" is raised.");
168
169#define INT_TO_BYTES_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300170 {"to_bytes", (PyCFunction)int_to_bytes, METH_FASTCALL|METH_KEYWORDS, int_to_bytes__doc__},
Serhiy Storchaka495e8802017-02-01 23:12:20 +0200171
172static PyObject *
173int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
174 int is_signed);
175
176static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200177int_to_bytes(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka495e8802017-02-01 23:12:20 +0200178{
179 PyObject *return_value = NULL;
180 static const char * const _keywords[] = {"length", "byteorder", "signed", NULL};
181 static _PyArg_Parser _parser = {"nU|$p:to_bytes", _keywords, 0};
182 Py_ssize_t length;
183 PyObject *byteorder;
184 int is_signed = 0;
185
186 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
187 &length, &byteorder, &is_signed)) {
188 goto exit;
189 }
190 return_value = int_to_bytes_impl(self, length, byteorder, is_signed);
191
192exit:
193 return return_value;
194}
195
196PyDoc_STRVAR(int_from_bytes__doc__,
197"from_bytes($type, /, bytes, byteorder, *, signed=False)\n"
198"--\n"
199"\n"
200"Return the integer represented by the given array of bytes.\n"
201"\n"
202" bytes\n"
203" Holds the array of bytes to convert. The argument must either\n"
204" support the buffer protocol or be an iterable object producing bytes.\n"
205" Bytes and bytearray are examples of built-in objects that support the\n"
206" buffer protocol.\n"
207" byteorder\n"
208" The byte order used to represent the integer. If byteorder is \'big\',\n"
209" the most significant byte is at the beginning of the byte array. If\n"
210" byteorder is \'little\', the most significant byte is at the end of the\n"
211" byte array. To request the native byte order of the host system, use\n"
212" `sys.byteorder\' as the byte order value.\n"
213" signed\n"
214" Indicates whether two\'s complement is used to represent the integer.");
215
216#define INT_FROM_BYTES_METHODDEF \
Serhiy Storchaka6969eaf2017-07-03 21:20:15 +0300217 {"from_bytes", (PyCFunction)int_from_bytes, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, int_from_bytes__doc__},
Serhiy Storchaka495e8802017-02-01 23:12:20 +0200218
219static PyObject *
220int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
221 PyObject *byteorder, int is_signed);
222
223static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200224int_from_bytes(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka495e8802017-02-01 23:12:20 +0200225{
226 PyObject *return_value = NULL;
227 static const char * const _keywords[] = {"bytes", "byteorder", "signed", NULL};
228 static _PyArg_Parser _parser = {"OU|$p:from_bytes", _keywords, 0};
229 PyObject *bytes_obj;
230 PyObject *byteorder;
231 int is_signed = 0;
232
233 if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
234 &bytes_obj, &byteorder, &is_signed)) {
235 goto exit;
236 }
237 return_value = int_from_bytes_impl(type, bytes_obj, byteorder, is_signed);
238
239exit:
240 return return_value;
241}
Lisa Roach5ac70432018-09-13 23:56:23 -0700242/*[clinic end generated code: output=6d5e92d7dc803751 input=a9049054013a1b77]*/