1/*[clinic input] 2preserve 3[clinic start generated code]*/ 4 5PyDoc_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 14static PyObject * 15float_is_integer_impl(PyObject *self); 16 17static PyObject * 18float_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored)) 19{ 20 return float_is_integer_impl(self); 21} 22 23PyDoc_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 32static PyObject * 33float___trunc___impl(PyObject *self); 34 35static PyObject * 36float___trunc__(PyObject *self, PyObject *Py_UNUSED(ignored)) 37{ 38 return float___trunc___impl(self); 39} 40 41PyDoc_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 50static PyObject * 51float___floor___impl(PyObject *self); 52 53static PyObject * 54float___floor__(PyObject *self, PyObject *Py_UNUSED(ignored)) 55{ 56 return float___floor___impl(self); 57} 58 59PyDoc_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 68static PyObject * 69float___ceil___impl(PyObject *self); 70 71static PyObject * 72float___ceil__(PyObject *self, PyObject *Py_UNUSED(ignored)) 73{ 74 return float___ceil___impl(self); 75} 76 77PyDoc_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 88static PyObject * 89float___round___impl(PyObject *self, PyObject *o_ndigits); 90 91static PyObject * 92float___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) { 101 goto skip_optional; 102 } 103 o_ndigits = args[0]; 104skip_optional: 105 return_value = float___round___impl(self, o_ndigits); 106 107exit: 108 return return_value; 109} 110 111PyDoc_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 120static PyObject * 121float_conjugate_impl(PyObject *self); 122 123static PyObject * 124float_conjugate(PyObject *self, PyObject *Py_UNUSED(ignored)) 125{ 126 return float_conjugate_impl(self); 127} 128 129PyDoc_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 143static PyObject * 144float_hex_impl(PyObject *self); 145 146static PyObject * 147float_hex(PyObject *self, PyObject *Py_UNUSED(ignored)) 148{ 149 return float_hex_impl(self); 150} 151 152PyDoc_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 166PyDoc_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 187static PyObject * 188float_as_integer_ratio_impl(PyObject *self); 189 190static PyObject * 191float_as_integer_ratio(PyObject *self, PyObject *Py_UNUSED(ignored)) 192{ 193 return float_as_integer_ratio_impl(self); 194} 195 196PyDoc_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 202static PyObject * 203float_new_impl(PyTypeObject *type, PyObject *x); 204 205static PyObject * 206float_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) 207{ 208 PyObject *return_value = NULL; 209 PyObject *x = NULL; 210 211 if ((type == &PyFloat_Type || 212 type->tp_init == PyFloat_Type.tp_init) && 213 !_PyArg_NoKeywords("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) { 220 goto skip_optional; 221 } 222 x = PyTuple_GET_ITEM(args, 0); 223skip_optional: 224 return_value = float_new_impl(type, x); 225 226exit: 227 return return_value; 228} 229 230PyDoc_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 238static PyObject * 239float___getnewargs___impl(PyObject *self); 240 241static PyObject * 242float___getnewargs__(PyObject *self, PyObject *Py_UNUSED(ignored)) 243{ 244 return float___getnewargs___impl(self); 245} 246 247PyDoc_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 265static PyObject * 266float___getformat___impl(PyTypeObject *type, const char *typestr); 267 268static PyObject * 269float___getformat__(PyTypeObject *type, PyObject *arg) 270{ 271 PyObject *return_value = NULL; 272 const char *typestr; 273 274 if (!PyUnicode_Check(arg)) { 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) { 281 goto exit; 282 } 283 if (strlen(typestr) != (size_t)typestr_length) { 284 PyErr_SetString(PyExc_ValueError, "embedded null character"); 285 goto exit; 286 } 287 return_value = float___getformat___impl(type, typestr); 288 289exit: 290 return return_value; 291} 292 293PyDoc_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 302static PyObject * 303float___format___impl(PyObject *self, PyObject *format_spec); 304 305static PyObject * 306float___format__(PyObject *self, PyObject *arg) 307{ 308 PyObject *return_value = NULL; 309 PyObject *format_spec; 310 311 if (!PyUnicode_Check(arg)) { 312 _PyArg_BadArgument("__format__", "argument", "str", arg); 313 goto exit; 314 } 315 if (PyUnicode_READY(arg) == -1) { 316 goto exit; 317 } 318 format_spec = arg; 319 return_value = float___format___impl(self, format_spec); 320 321exit: 322 return return_value; 323} 324/*[clinic end generated code: output=a6e6467624a92a43 input=a9049054013a1b77]*/ 325