• 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)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 = NULL;
60 
61     if (!_PyArg_UnpackStack(args, nargs, "__round__",
62         0, 1,
63         &o_ndigits)) {
64         goto exit;
65     }
66     return_value = float___round___impl(self, o_ndigits);
67 
68 exit:
69     return return_value;
70 }
71 
72 PyDoc_STRVAR(float_conjugate__doc__,
73 "conjugate($self, /)\n"
74 "--\n"
75 "\n"
76 "Return self, the complex conjugate of any float.");
77 
78 #define FLOAT_CONJUGATE_METHODDEF    \
79     {"conjugate", (PyCFunction)float_conjugate, METH_NOARGS, float_conjugate__doc__},
80 
81 static PyObject *
82 float_conjugate_impl(PyObject *self);
83 
84 static PyObject *
float_conjugate(PyObject * self,PyObject * Py_UNUSED (ignored))85 float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored))
86 {
87     return float_conjugate_impl(self);
88 }
89 
90 PyDoc_STRVAR(float_hex__doc__,
91 "hex($self, /)\n"
92 "--\n"
93 "\n"
94 "Return a hexadecimal representation of a floating-point number.\n"
95 "\n"
96 ">>> (-0.1).hex()\n"
97 "\'-0x1.999999999999ap-4\'\n"
98 ">>> 3.14159.hex()\n"
99 "\'0x1.921f9f01b866ep+1\'");
100 
101 #define FLOAT_HEX_METHODDEF    \
102     {"hex", (PyCFunction)float_hex, METH_NOARGS, float_hex__doc__},
103 
104 static PyObject *
105 float_hex_impl(PyObject *self);
106 
107 static PyObject *
float_hex(PyObject * self,PyObject * Py_UNUSED (ignored))108 float_hex(PyObject *self, PyObject *Py_UNUSED(ignored))
109 {
110     return float_hex_impl(self);
111 }
112 
113 PyDoc_STRVAR(float_fromhex__doc__,
114 "fromhex($type, string, /)\n"
115 "--\n"
116 "\n"
117 "Create a floating-point number from a hexadecimal string.\n"
118 "\n"
119 ">>> float.fromhex(\'0x1.ffffp10\')\n"
120 "2047.984375\n"
121 ">>> float.fromhex(\'-0x1p-1074\')\n"
122 "-5e-324");
123 
124 #define FLOAT_FROMHEX_METHODDEF    \
125     {"fromhex", (PyCFunction)float_fromhex, METH_O|METH_CLASS, float_fromhex__doc__},
126 
127 PyDoc_STRVAR(float_as_integer_ratio__doc__,
128 "as_integer_ratio($self, /)\n"
129 "--\n"
130 "\n"
131 "Return integer ratio.\n"
132 "\n"
133 "Return a pair of integers, whose ratio is exactly equal to the original float\n"
134 "and with a positive denominator.\n"
135 "\n"
136 "Raise OverflowError on infinities and a ValueError on NaNs.\n"
137 "\n"
138 ">>> (10.0).as_integer_ratio()\n"
139 "(10, 1)\n"
140 ">>> (0.0).as_integer_ratio()\n"
141 "(0, 1)\n"
142 ">>> (-.25).as_integer_ratio()\n"
143 "(-1, 4)");
144 
145 #define FLOAT_AS_INTEGER_RATIO_METHODDEF    \
146     {"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, float_as_integer_ratio__doc__},
147 
148 static PyObject *
149 float_as_integer_ratio_impl(PyObject *self);
150 
151 static PyObject *
float_as_integer_ratio(PyObject * self,PyObject * Py_UNUSED (ignored))152 float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored))
153 {
154     return float_as_integer_ratio_impl(self);
155 }
156 
157 PyDoc_STRVAR(float_new__doc__,
158 "float(x=0, /)\n"
159 "--\n"
160 "\n"
161 "Convert a string or number to a floating point number, if possible.");
162 
163 static PyObject *
164 float_new_impl(PyTypeObject *type, PyObject *x);
165 
166 static PyObject *
float_new(PyTypeObject * type,PyObject * args,PyObject * kwargs)167 float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
168 {
169     PyObject *return_value = NULL;
170     PyObject *x = _PyLong_Zero;
171 
172     if ((type == &PyFloat_Type) &&
173         !_PyArg_NoKeywords("float", kwargs)) {
174         goto exit;
175     }
176     if (!PyArg_UnpackTuple(args, "float",
177         0, 1,
178         &x)) {
179         goto exit;
180     }
181     return_value = float_new_impl(type, x);
182 
183 exit:
184     return return_value;
185 }
186 
187 PyDoc_STRVAR(float___getnewargs____doc__,
188 "__getnewargs__($self, /)\n"
189 "--\n"
190 "\n");
191 
192 #define FLOAT___GETNEWARGS___METHODDEF    \
193     {"__getnewargs__", (PyCFunction)float___getnewargs__, METH_NOARGS, float___getnewargs____doc__},
194 
195 static PyObject *
196 float___getnewargs___impl(PyObject *self);
197 
198 static PyObject *
float___getnewargs__(PyObject * self,PyObject * Py_UNUSED (ignored))199 float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored))
200 {
201     return float___getnewargs___impl(self);
202 }
203 
204 PyDoc_STRVAR(float___getformat____doc__,
205 "__getformat__($type, typestr, /)\n"
206 "--\n"
207 "\n"
208 "You probably don\'t want to use this function.\n"
209 "\n"
210 "  typestr\n"
211 "    Must be \'double\' or \'float\'.\n"
212 "\n"
213 "It exists mainly to be used in Python\'s test suite.\n"
214 "\n"
215 "This function returns whichever of \'unknown\', \'IEEE, big-endian\' or \'IEEE,\n"
216 "little-endian\' best describes the format of floating point numbers used by the\n"
217 "C type named by typestr.");
218 
219 #define FLOAT___GETFORMAT___METHODDEF    \
220     {"__getformat__", (PyCFunction)float___getformat__, METH_O|METH_CLASS, float___getformat____doc__},
221 
222 static PyObject *
223 float___getformat___impl(PyTypeObject *type, const char *typestr);
224 
225 static PyObject *
float___getformat__(PyTypeObject * type,PyObject * arg)226 float___getformat__(PyTypeObject *type, PyObject *arg)
227 {
228     PyObject *return_value = NULL;
229     const char *typestr;
230 
231     if (!PyArg_Parse(arg, "s:__getformat__", &typestr)) {
232         goto exit;
233     }
234     return_value = float___getformat___impl(type, typestr);
235 
236 exit:
237     return return_value;
238 }
239 
240 PyDoc_STRVAR(float___set_format____doc__,
241 "__set_format__($type, typestr, fmt, /)\n"
242 "--\n"
243 "\n"
244 "You probably don\'t want to use this function.\n"
245 "\n"
246 "  typestr\n"
247 "    Must be \'double\' or \'float\'.\n"
248 "  fmt\n"
249 "    Must be one of \'unknown\', \'IEEE, big-endian\' or \'IEEE, little-endian\',\n"
250 "    and in addition can only be one of the latter two if it appears to\n"
251 "    match the underlying C reality.\n"
252 "\n"
253 "It exists mainly to be used in Python\'s test suite.\n"
254 "\n"
255 "Override the automatic determination of C-level floating point type.\n"
256 "This affects how floats are converted to and from binary strings.");
257 
258 #define FLOAT___SET_FORMAT___METHODDEF    \
259     {"__set_format__", (PyCFunction)float___set_format__, METH_FASTCALL|METH_CLASS, float___set_format____doc__},
260 
261 static PyObject *
262 float___set_format___impl(PyTypeObject *type, const char *typestr,
263                           const char *fmt);
264 
265 static PyObject *
float___set_format__(PyTypeObject * type,PyObject * const * args,Py_ssize_t nargs)266 float___set_format__(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs)
267 {
268     PyObject *return_value = NULL;
269     const char *typestr;
270     const char *fmt;
271 
272     if (!_PyArg_ParseStack(args, nargs, "ss:__set_format__",
273         &typestr, &fmt)) {
274         goto exit;
275     }
276     return_value = float___set_format___impl(type, typestr, fmt);
277 
278 exit:
279     return return_value;
280 }
281 
282 PyDoc_STRVAR(float___format____doc__,
283 "__format__($self, format_spec, /)\n"
284 "--\n"
285 "\n"
286 "Formats the float according to format_spec.");
287 
288 #define FLOAT___FORMAT___METHODDEF    \
289     {"__format__", (PyCFunction)float___format__, METH_O, float___format____doc__},
290 
291 static PyObject *
292 float___format___impl(PyObject *self, PyObject *format_spec);
293 
294 static PyObject *
float___format__(PyObject * self,PyObject * arg)295 float___format__(PyObject *self, PyObject *arg)
296 {
297     PyObject *return_value = NULL;
298     PyObject *format_spec;
299 
300     if (!PyArg_Parse(arg, "U:__format__", &format_spec)) {
301         goto exit;
302     }
303     return_value = float___format___impl(self, format_spec);
304 
305 exit:
306     return return_value;
307 }
308 /*[clinic end generated code: output=a3c366a156be61f9 input=a9049054013a1b77]*/
309