Debian Codegraph @

Objects/clinic/floatobject.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
6
7 PyDoc_STRVAR(float_is_integer__doc__,
8 "is_integer($self, /)\n"
9 "--\n"
10 "\n"
11 "Return True if the float is an integer.");
12
13 #define FLOAT_IS_INTEGER_METHODDEF \
14 {"is_integer", (PyCFunction)float_is_integer, METH_NOARGS, float_is_integer__doc__},
15
16 static PyObject *
17 float_is_integer_impl(PyObject *self);
18
19 static PyObject *
20 float_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
21 {
22 return float_is_integer_impl(self);
23 }
24
25 PyDoc_STRVAR(float___trunc____doc__,
26 "__trunc__($self, /)\n"
27 "--\n"
28 "\n"
29 "Return the Integral closest to x between 0 and x.");
30
31 #define FLOAT___TRUNC___METHODDEF \
32 {"__trunc__", (PyCFunction)float___trunc__, METH_NOARGS, float___trunc____doc__},
33
34 static PyObject *
35 float___trunc___impl(PyObject *self);
36
37 static PyObject *
38 float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored))
39 {
40 return float___trunc___impl(self);
41 }
42
43 PyDoc_STRVAR(float___floor____doc__,
44 "__floor__($self, /)\n"
45 "--\n"
46 "\n"
47 "Return the floor as an Integral.");
48
49 #define FLOAT___FLOOR___METHODDEF \
50 {"__floor__", (PyCFunction)float___floor__, METH_NOARGS, float___floor____doc__},
51
52 static PyObject *
53 float___floor___impl(PyObject *self);
54
55 static PyObject *
56 float___floor__(PyObject *self, PyObject *Py_UNUSED(ignored))
57 {
58 return float___floor___impl(self);
59 }
60
61 PyDoc_STRVAR(float___ceil____doc__,
62 "__ceil__($self, /)\n"
63 "--\n"
64 "\n"
65 "Return the ceiling as an Integral.");
66
67 #define FLOAT___CEIL___METHODDEF \
68 {"__ceil__", (PyCFunction)float___ceil__, METH_NOARGS, float___ceil____doc__},
69
70 static PyObject *
71 float___ceil___impl(PyObject *self);
72
73 static PyObject *
74 float___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored))
75 {
76 return float___ceil___impl(self);
77 }
78
79 PyDoc_STRVAR(float___round____doc__,
80 "__round__($self, ndigits=None, /)\n"
81 "--\n"
82 "\n"
83 "Return the Integral closest to x, rounding half toward even.\n"
84 "\n"
85 "When an argument is passed, work like built-in round(x, ndigits).");
86
87 #define FLOAT___ROUND___METHODDEF \
88 {"__round__", _PyCFunction_CAST(float___round__), METH_FASTCALL, float___round____doc__},
89
90 static PyObject *
91 float___round___impl(PyObject *self, PyObject *o_ndigits);
92
93 static PyObject *
94 float___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
95 {
96 PyObject *return_value = NULL;
97 PyObject *o_ndigits = Py_None;
98
99 if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
100 goto exit;
101 }
102 if (nargs < 1) {
103 goto skip_optional;
104 }
105 o_ndigits = args[0];
106 skip_optional:
107 return_value = float___round___impl(self, o_ndigits);
108
109 exit:
110 return return_value;
111 }
112
113 PyDoc_STRVAR(float_conjugate__doc__,
114 "conjugate($self, /)\n"
115 "--\n"
116 "\n"
117 "Return self, the complex conjugate of any float.");
118
119 #define FLOAT_CONJUGATE_METHODDEF \
120 {"conjugate", (PyCFunction)float_conjugate, METH_NOARGS, float_conjugate__doc__},
121
122 static PyObject *
123 float_conjugate_impl(PyObject *self);
124
125 static PyObject *
126 float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
127 {
128 return float_conjugate_impl(self);
129 }
130
131 PyDoc_STRVAR(float_hex__doc__,
132 "hex($self, /)\n"
133 "--\n"
134 "\n"
135 "Return a hexadecimal representation of a floating-point number.\n"
136 "\n"
137 ">>> (-0.1).hex()\n"
138 "\'-0x1.999999999999ap-4\'\n"
139 ">>> 3.14159.hex()\n"
140 "\'0x1.921f9f01b866ep+1\'");
141
142 #define FLOAT_HEX_METHODDEF \
143 {"hex", (PyCFunction)float_hex, METH_NOARGS, float_hex__doc__},
144
145 static PyObject *
146 float_hex_impl(PyObject *self);
147
148 static PyObject *
149 float_hex(PyObject *self, PyObject *Py_UNUSED(ignored))
150 {
151 return float_hex_impl(self);
152 }
153
154 PyDoc_STRVAR(float_fromhex__doc__,
155 "fromhex($type, string, /)\n"
156 "--\n"
157 "\n"
158 "Create a floating-point number from a hexadecimal string.\n"
159 "\n"
160 ">>> float.fromhex(\'0x1.ffffp10\')\n"
161 "2047.984375\n"
162 ">>> float.fromhex(\'-0x1p-1074\')\n"
163 "-5e-324");
164
165 #define FLOAT_FROMHEX_METHODDEF \
166 {"fromhex", (PyCFunction)float_fromhex, METH_O|METH_CLASS, float_fromhex__doc__},
167
168 static PyObject *
169 float_fromhex_impl(PyTypeObject *type, PyObject *string);
170
171 static PyObject *
172 float_fromhex(PyObject *type, PyObject *string)
173 {
174 PyObject *return_value = NULL;
175
176 return_value = float_fromhex_impl((PyTypeObject *)type, string);
177
178 return return_value;
179 }
180
181 PyDoc_STRVAR(float_as_integer_ratio__doc__,
182 "as_integer_ratio($self, /)\n"
183 "--\n"
184 "\n"
185 "Return a pair of integers, whose ratio is exactly equal to the original float.\n"
186 "\n"
187 "The ratio is in lowest terms and has a positive denominator. Raise\n"
188 "OverflowError on infinities and a ValueError on NaNs.\n"
189 "\n"
190 ">>> (10.0).as_integer_ratio()\n"
191 "(10, 1)\n"
192 ">>> (0.0).as_integer_ratio()\n"
193 "(0, 1)\n"
194 ">>> (-.25).as_integer_ratio()\n"
195 "(-1, 4)");
196
197 #define FLOAT_AS_INTEGER_RATIO_METHODDEF \
198 {"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, float_as_integer_ratio__doc__},
199
200 static PyObject *
201 float_as_integer_ratio_impl(PyObject *self);
202
203 static PyObject *
204 float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
205 {
206 return float_as_integer_ratio_impl(self);
207 }
208
209 PyDoc_STRVAR(float_new__doc__,
210 "float(x=0, /)\n"
211 "--\n"
212 "\n"
213 "Convert a string or number to a floating-point number, if possible.");
214
215 static PyObject *
216 float_new_impl(PyTypeObject *type, PyObject *x);
217
218 static PyObject *
219 float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
220 {
221 PyObject *return_value = NULL;
222 PyTypeObject *base_tp = &PyFloat_Type;
223 PyObject *x = NULL;
224
225 if ((type == base_tp || type->tp_init == base_tp->tp_init) &&
226 !_PyArg_NoKeywords("float", kwargs)) {
227 goto exit;
228 }
229 if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) {
230 goto exit;
231 }
232 if (PyTuple_GET_SIZE(args) < 1) {
233 goto skip_optional;
234 }
235 x = PyTuple_GET_ITEM(args, 0);
236 skip_optional:
237 return_value = float_new_impl(type, x);
238
239 exit:
240 return return_value;
241 }
242
243 PyDoc_STRVAR(float_from_number__doc__,
244 "from_number($type, number, /)\n"
245 "--\n"
246 "\n"
247 "Convert real number to a floating-point number.");
248
249 #define FLOAT_FROM_NUMBER_METHODDEF \
250 {"from_number", (PyCFunction)float_from_number, METH_O|METH_CLASS, float_from_number__doc__},
251
252 static PyObject *
253 float_from_number_impl(PyTypeObject *type, PyObject *number);
254
255 static PyObject *
256 float_from_number(PyObject *type, PyObject *number)
257 {
258 PyObject *return_value = NULL;
259
260 return_value = float_from_number_impl((PyTypeObject *)type, number);
261
262 return return_value;
263 }
264
265 PyDoc_STRVAR(float___getnewargs____doc__,
266 "__getnewargs__($self, /)\n"
267 "--\n"
268 "\n");
269
270 #define FLOAT___GETNEWARGS___METHODDEF \
271 {"__getnewargs__", (PyCFunction)float___getnewargs__, METH_NOARGS, float___getnewargs____doc__},
272
273 static PyObject *
274 float___getnewargs___impl(PyObject *self);
275
276 static PyObject *
277 float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
278 {
279 return float___getnewargs___impl(self);
280 }
281
282 PyDoc_STRVAR(float___getformat____doc__,
283 "__getformat__($type, typestr, /)\n"
284 "--\n"
285 "\n"
286 "You probably don\'t want to use this function.\n"
287 "\n"
288 " typestr\n"
289 " Must be \'double\' or \'float\'.\n"
290 "\n"
291 "It exists mainly to be used in Python\'s test suite.\n"
292 "\n"
293 "This function returns whichever of \'unknown\', \'IEEE, big-endian\' or \'IEEE,\n"
294 "little-endian\' best describes the format of floating-point numbers used by the\n"
295 "C type named by typestr.");
296
297 #define FLOAT___GETFORMAT___METHODDEF \
298 {"__getformat__", (PyCFunction)float___getformat__, METH_O|METH_CLASS, float___getformat____doc__},
299
300 static PyObject *
301 float___getformat___impl(PyTypeObject *type, const char *typestr);
302
303 static PyObject *
304 float___getformat__(PyObject *type, PyObject *arg)
305 {
306 PyObject *return_value = NULL;
307 const char *typestr;
308
309 if (!PyUnicode_Check(arg)) {
310 _PyArg_BadArgument("__getformat__", "argument", "str", arg);
311 goto exit;
312 }
313 Py_ssize_t typestr_length;
314 typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length);
315 if (typestr == NULL) {
316 goto exit;
317 }
318 if (strlen(typestr) != (size_t)typestr_length) {
319 PyErr_SetString(PyExc_ValueError, "embedded null character");
320 goto exit;
321 }
322 return_value = float___getformat___impl((PyTypeObject *)type, typestr);
323
324 exit:
325 return return_value;
326 }
327
328 PyDoc_STRVAR(float___format____doc__,
329 "__format__($self, format_spec, /)\n"
330 "--\n"
331 "\n"
332 "Formats the float according to format_spec.");
333
334 #define FLOAT___FORMAT___METHODDEF \
335 {"__format__", (PyCFunction)float___format__, METH_O, float___format____doc__},
336
337 static PyObject *
338 float___format___impl(PyObject *self, PyObject *format_spec);
339
340 static PyObject *
341 float___format__(PyObject *self, PyObject *arg)
342 {
343 PyObject *return_value = NULL;
344 PyObject *format_spec;
345
346 if (!PyUnicode_Check(arg)) {
347 _PyArg_BadArgument("__format__", "argument", "str", arg);
348 goto exit;
349 }
350 format_spec = arg;
351 return_value = float___format___impl(self, format_spec);
352
353 exit:
354 return return_value;
355 }
356 /*[clinic end generated code: output=927035897ea3573f input=a9049054013a1b77]*/