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