• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *
float_is_integer(PyObject * self,PyObject * Py_UNUSED (ignored))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 *
float___trunc__(PyObject * self,PyObject * Py_UNUSED (ignored))36 float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored))
37 {
38     return float___trunc___impl(self);
39 }
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 *
float___round__(PyObject * self,PyObject * const * args,Py_ssize_t nargs)56 float___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
57 {
58     PyObject *return_value = NULL;
59     PyObject *o_ndigits = Py_None;
60 
61     if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) {
62         goto exit;
63     }
64     if (nargs < 1) {
65         goto skip_optional;
66     }
67     o_ndigits = args[0];
68 skip_optional:
69     return_value = float___round___impl(self, o_ndigits);
70 
71 exit:
72     return return_value;
73 }
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 *
float_conjugate(PyObject * self,PyObject * Py_UNUSED (ignored))88 float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
89 {
90     return float_conjugate_impl(self);
91 }
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 *
float_hex(PyObject * self,PyObject * Py_UNUSED (ignored))111 float_hex(PyObject *self, PyObject *Py_UNUSED(ignored))
112 {
113     return float_hex_impl(self);
114 }
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 *
float_as_integer_ratio(PyObject * self,PyObject * Py_UNUSED (ignored))155 float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
156 {
157     return float_as_integer_ratio_impl(self);
158 }
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 *
float_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)170 float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
171 {
172     PyObject *return_value = NULL;
173     PyObject *x = _PyLong_Zero;
174 
175     if ((type == &PyFloat_Type) &&
176         !_PyArg_NoKeywords("float", kwargs)) {
177         goto exit;
178     }
179     if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) {
180         goto exit;
181     }
182     if (PyTuple_GET_SIZE(args) < 1) {
183         goto skip_optional;
184     }
185     x = PyTuple_GET_ITEM(args, 0);
186 skip_optional:
187     return_value = float_new_impl(type, x);
188 
189 exit:
190     return return_value;
191 }
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 *
float___getnewargs__(PyObject * self,PyObject * Py_UNUSED (ignored))205 float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
206 {
207     return float___getnewargs___impl(self);
208 }
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 *
float___getformat__(PyTypeObject * type,PyObject * arg)232 float___getformat__(PyTypeObject *type, PyObject *arg)
233 {
234     PyObject *return_value = NULL;
235     const char *typestr;
236 
237     if (!PyUnicode_Check(arg)) {
238         _PyArg_BadArgument("__getformat__", "argument", "str", arg);
239         goto exit;
240     }
241     Py_ssize_t typestr_length;
242     typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length);
243     if (typestr == NULL) {
244         goto exit;
245     }
246     if (strlen(typestr) != (size_t)typestr_length) {
247         PyErr_SetString(PyExc_ValueError, "embedded null character");
248         goto exit;
249     }
250     return_value = float___getformat___impl(type, typestr);
251 
252 exit:
253     return return_value;
254 }
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 *
float___set_format__(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)282 float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
283 {
284     PyObject *return_value = NULL;
285     const char *typestr;
286     const char *fmt;
287 
288     if (!_PyArg_CheckPositional("__set_format__", nargs, 2, 2)) {
289         goto exit;
290     }
291     if (!PyUnicode_Check(args[0])) {
292         _PyArg_BadArgument("__set_format__", "argument 1", "str", args[0]);
293         goto exit;
294     }
295     Py_ssize_t typestr_length;
296     typestr = PyUnicode_AsUTF8AndSize(args[0], &typestr_length);
297     if (typestr == NULL) {
298         goto exit;
299     }
300     if (strlen(typestr) != (size_t)typestr_length) {
301         PyErr_SetString(PyExc_ValueError, "embedded null character");
302         goto exit;
303     }
304     if (!PyUnicode_Check(args[1])) {
305         _PyArg_BadArgument("__set_format__", "argument 2", "str", args[1]);
306         goto exit;
307     }
308     Py_ssize_t fmt_length;
309     fmt = PyUnicode_AsUTF8AndSize(args[1], &fmt_length);
310     if (fmt == NULL) {
311         goto exit;
312     }
313     if (strlen(fmt) != (size_t)fmt_length) {
314         PyErr_SetString(PyExc_ValueError, "embedded null character");
315         goto exit;
316     }
317     return_value = float___set_format___impl(type, typestr, fmt);
318 
319 exit:
320     return return_value;
321 }
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 *
float___format__(PyObject * self,PyObject * arg)336 float___format__(PyObject *self, PyObject *arg)
337 {
338     PyObject *return_value = NULL;
339     PyObject *format_spec;
340 
341     if (!PyUnicode_Check(arg)) {
342         _PyArg_BadArgument("__format__", "argument", "str", arg);
343         goto exit;
344     }
345     if (PyUnicode_READY(arg) == -1) {
346         goto exit;
347     }
348     format_spec = arg;
349     return_value = float___format___impl(self, format_spec);
350 
351 exit:
352     return return_value;
353 }
354 /*[clinic end generated code: output=1676433b9f04fbc9 input=a9049054013a1b77]*/
355