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