| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | /*[clinic input]
 | 
					
						
							|  |  |  | preserve | 
					
						
							|  |  |  | [clinic start generated code]*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-17 14:30:31 +02:00
										 |  |  | #include "pycore_modsupport.h"    // _PyArg_CheckPositional()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | PyDoc_STRVAR(float_is_integer__doc__, | 
					
						
							|  |  |  | "is_integer($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return True if the float is an integer."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT_IS_INTEGER_METHODDEF    \
 | 
					
						
							|  |  |  |     {"is_integer", (PyCFunction)float_is_integer, METH_NOARGS, float_is_integer__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_is_integer_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float_is_integer_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float___trunc____doc__, | 
					
						
							|  |  |  | "__trunc__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return the Integral closest to x between 0 and x."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___TRUNC___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__trunc__", (PyCFunction)float___trunc__, METH_NOARGS, float___trunc____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___trunc___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float___trunc___impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 01:00:28 +03:00
										 |  |  | PyDoc_STRVAR(float___floor____doc__, | 
					
						
							|  |  |  | "__floor__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return the floor as an Integral."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___FLOOR___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__floor__", (PyCFunction)float___floor__, METH_NOARGS, float___floor____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___floor___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___floor__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float___floor___impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float___ceil____doc__, | 
					
						
							|  |  |  | "__ceil__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return the ceiling as an Integral."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___CEIL___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__ceil__", (PyCFunction)float___ceil__, METH_NOARGS, float___ceil____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___ceil___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float___ceil___impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | PyDoc_STRVAR(float___round____doc__, | 
					
						
							|  |  |  | "__round__($self, ndigits=None, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return the Integral closest to x, rounding half toward even.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "When an argument is passed, work like built-in round(x, ndigits)."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___ROUND___METHODDEF    \
 | 
					
						
							| 
									
										
										
										
											2022-05-03 20:25:41 +02:00
										 |  |  |     {"__round__", _PyCFunction_CAST(float___round__), METH_FASTCALL, float___round____doc__}, | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___round___impl(PyObject *self, PyObject *o_ndigits); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							| 
									
										
										
										
											2017-12-15 13:11:11 +02:00
										 |  |  | float___round__(PyObject *self, PyObject *const *args, Py_ssize_t nargs) | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2019-09-14 12:24:05 +03:00
										 |  |  |     PyObject *o_ndigits = Py_None; | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-11 18:01:42 +02:00
										 |  |  |     if (!_PyArg_CheckPositional("__round__", nargs, 0, 1)) { | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-11 18:01:42 +02:00
										 |  |  |     if (nargs < 1) { | 
					
						
							|  |  |  |         goto skip_optional; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     o_ndigits = args[0]; | 
					
						
							|  |  |  | skip_optional: | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  |     return_value = float___round___impl(self, o_ndigits); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float_conjugate__doc__, | 
					
						
							|  |  |  | "conjugate($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return self, the complex conjugate of any float."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT_CONJUGATE_METHODDEF    \
 | 
					
						
							|  |  |  |     {"conjugate", (PyCFunction)float_conjugate, METH_NOARGS, float_conjugate__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_conjugate_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float_conjugate_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float_hex__doc__, | 
					
						
							|  |  |  | "hex($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Return a hexadecimal representation of a floating-point number.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | ">>> (-0.1).hex()\n" | 
					
						
							|  |  |  | "\'-0x1.999999999999ap-4\'\n" | 
					
						
							|  |  |  | ">>> 3.14159.hex()\n" | 
					
						
							|  |  |  | "\'0x1.921f9f01b866ep+1\'"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT_HEX_METHODDEF    \
 | 
					
						
							|  |  |  |     {"hex", (PyCFunction)float_hex, METH_NOARGS, float_hex__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_hex_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_hex(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float_hex_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float_fromhex__doc__, | 
					
						
							|  |  |  | "fromhex($type, string, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Create a floating-point number from a hexadecimal string.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | ">>> float.fromhex(\'0x1.ffffp10\')\n" | 
					
						
							|  |  |  | "2047.984375\n" | 
					
						
							|  |  |  | ">>> float.fromhex(\'-0x1p-1074\')\n" | 
					
						
							|  |  |  | "-5e-324"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT_FROMHEX_METHODDEF    \
 | 
					
						
							|  |  |  |     {"fromhex", (PyCFunction)float_fromhex, METH_O|METH_CLASS, float_fromhex__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float_as_integer_ratio__doc__, | 
					
						
							|  |  |  | "as_integer_ratio($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2023-02-27 22:11:28 +03:00
										 |  |  | "Return a pair of integers, whose ratio is exactly equal to the original float.\n" | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | "\n" | 
					
						
							| 
									
										
										
										
											2023-02-27 22:11:28 +03:00
										 |  |  | "The ratio is in lowest terms and has a positive denominator.  Raise\n" | 
					
						
							|  |  |  | "OverflowError on infinities and a ValueError on NaNs.\n" | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | "\n" | 
					
						
							|  |  |  | ">>> (10.0).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(10, 1)\n" | 
					
						
							|  |  |  | ">>> (0.0).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(0, 1)\n" | 
					
						
							|  |  |  | ">>> (-.25).as_integer_ratio()\n" | 
					
						
							|  |  |  | "(-1, 4)"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT_AS_INTEGER_RATIO_METHODDEF    \
 | 
					
						
							|  |  |  |     {"as_integer_ratio", (PyCFunction)float_as_integer_ratio, METH_NOARGS, float_as_integer_ratio__doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_as_integer_ratio_impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float_as_integer_ratio_impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  | PyDoc_STRVAR(float_new__doc__, | 
					
						
							|  |  |  | "float(x=0, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Convert a string or number to a floating point number, if possible."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_new_impl(PyTypeObject *type, PyObject *x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							| 
									
										
										
										
											2023-01-31 21:42:03 +01:00
										 |  |  |     PyTypeObject *base_tp = &PyFloat_Type; | 
					
						
							| 
									
										
										
										
											2020-10-27 02:24:34 +01:00
										 |  |  |     PyObject *x = NULL; | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-31 21:42:03 +01:00
										 |  |  |     if ((type == base_tp || type->tp_init == base_tp->tp_init) && | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |         !_PyArg_NoKeywords("float", kwargs)) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-11 18:01:42 +02:00
										 |  |  |     if (!_PyArg_CheckPositional("float", PyTuple_GET_SIZE(args), 0, 1)) { | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-01-11 18:01:42 +02:00
										 |  |  |     if (PyTuple_GET_SIZE(args) < 1) { | 
					
						
							|  |  |  |         goto skip_optional; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     x = PyTuple_GET_ITEM(args, 0); | 
					
						
							|  |  |  | skip_optional: | 
					
						
							| 
									
										
										
										
											2017-03-19 08:51:07 +02:00
										 |  |  |     return_value = float_new_impl(type, x); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  | PyDoc_STRVAR(float___getnewargs____doc__, | 
					
						
							|  |  |  | "__getnewargs__($self, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___GETNEWARGS___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__getnewargs__", (PyCFunction)float___getnewargs__, METH_NOARGS, float___getnewargs____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___getnewargs___impl(PyObject *self); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return float___getnewargs___impl(self); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float___getformat____doc__, | 
					
						
							|  |  |  | "__getformat__($type, typestr, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "You probably don\'t want to use this function.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "  typestr\n" | 
					
						
							|  |  |  | "    Must be \'double\' or \'float\'.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "It exists mainly to be used in Python\'s test suite.\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "This function returns whichever of \'unknown\', \'IEEE, big-endian\' or \'IEEE,\n" | 
					
						
							|  |  |  | "little-endian\' best describes the format of floating point numbers used by the\n" | 
					
						
							|  |  |  | "C type named by typestr."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___GETFORMAT___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__getformat__", (PyCFunction)float___getformat__, METH_O|METH_CLASS, float___getformat____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___getformat___impl(PyTypeObject *type, const char *typestr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___getformat__(PyTypeObject *type, PyObject *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							|  |  |  |     const char *typestr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |     if (!PyUnicode_Check(arg)) { | 
					
						
							| 
									
										
										
										
											2019-08-29 16:49:08 +02:00
										 |  |  |         _PyArg_BadArgument("__getformat__", "argument", "str", arg); | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-07 23:36:13 +01:00
										 |  |  |     Py_ssize_t typestr_length; | 
					
						
							|  |  |  |     typestr = PyUnicode_AsUTF8AndSize(arg, &typestr_length); | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |     if (typestr == NULL) { | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-07 23:36:13 +01:00
										 |  |  |     if (strlen(typestr) != (size_t)typestr_length) { | 
					
						
							|  |  |  |         PyErr_SetString(PyExc_ValueError, "embedded null character"); | 
					
						
							|  |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  |     return_value = float___getformat___impl(type, typestr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyDoc_STRVAR(float___format____doc__, | 
					
						
							|  |  |  | "__format__($self, format_spec, /)\n" | 
					
						
							|  |  |  | "--\n" | 
					
						
							|  |  |  | "\n" | 
					
						
							|  |  |  | "Formats the float according to format_spec."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define FLOAT___FORMAT___METHODDEF    \
 | 
					
						
							|  |  |  |     {"__format__", (PyCFunction)float___format__, METH_O, float___format____doc__}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___format___impl(PyObject *self, PyObject *format_spec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static PyObject * | 
					
						
							|  |  |  | float___format__(PyObject *self, PyObject *arg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     PyObject *return_value = NULL; | 
					
						
							|  |  |  |     PyObject *format_spec; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |     if (!PyUnicode_Check(arg)) { | 
					
						
							| 
									
										
										
										
											2019-08-29 16:49:08 +02:00
										 |  |  |         _PyArg_BadArgument("__format__", "argument", "str", arg); | 
					
						
							| 
									
										
										
										
											2018-12-25 13:23:47 +02:00
										 |  |  |         goto exit; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     format_spec = arg; | 
					
						
							| 
									
										
										
										
											2017-03-11 09:21:05 +02:00
										 |  |  |     return_value = float___format___impl(self, format_spec); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | exit: | 
					
						
							|  |  |  |     return return_value; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-07 23:36:13 +01:00
										 |  |  | /*[clinic end generated code: output=c79743c8551c30d9 input=a9049054013a1b77]*/ |