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