Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(math_gcd__doc__, |
| 6 | "gcd($module, x, y, /)\n" |
| 7 | "--\n" |
| 8 | "\n" |
| 9 | "greatest common divisor of x and y"); |
| 10 | |
| 11 | #define MATH_GCD_METHODDEF \ |
| 12 | {"gcd", (PyCFunction)math_gcd, METH_FASTCALL, math_gcd__doc__}, |
| 13 | |
| 14 | static PyObject * |
| 15 | math_gcd_impl(PyObject *module, PyObject *a, PyObject *b); |
| 16 | |
| 17 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 18 | math_gcd(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 19 | { |
| 20 | PyObject *return_value = NULL; |
| 21 | PyObject *a; |
| 22 | PyObject *b; |
| 23 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 24 | if (!_PyArg_UnpackStack(args, nargs, "gcd", |
| 25 | 2, 2, |
| 26 | &a, &b)) { |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 27 | goto exit; |
| 28 | } |
| 29 | return_value = math_gcd_impl(module, a, b); |
| 30 | |
| 31 | exit: |
| 32 | return return_value; |
| 33 | } |
| 34 | |
| 35 | PyDoc_STRVAR(math_ceil__doc__, |
| 36 | "ceil($module, x, /)\n" |
| 37 | "--\n" |
| 38 | "\n" |
| 39 | "Return the ceiling of x as an Integral.\n" |
| 40 | "\n" |
| 41 | "This is the smallest integer >= x."); |
| 42 | |
| 43 | #define MATH_CEIL_METHODDEF \ |
| 44 | {"ceil", (PyCFunction)math_ceil, METH_O, math_ceil__doc__}, |
| 45 | |
| 46 | PyDoc_STRVAR(math_floor__doc__, |
| 47 | "floor($module, x, /)\n" |
| 48 | "--\n" |
| 49 | "\n" |
| 50 | "Return the floor of x as an Integral.\n" |
| 51 | "\n" |
| 52 | "This is the largest integer <= x."); |
| 53 | |
| 54 | #define MATH_FLOOR_METHODDEF \ |
| 55 | {"floor", (PyCFunction)math_floor, METH_O, math_floor__doc__}, |
| 56 | |
| 57 | PyDoc_STRVAR(math_fsum__doc__, |
| 58 | "fsum($module, seq, /)\n" |
| 59 | "--\n" |
| 60 | "\n" |
| 61 | "Return an accurate floating point sum of values in the iterable seq.\n" |
| 62 | "\n" |
| 63 | "Assumes IEEE-754 floating point arithmetic."); |
| 64 | |
| 65 | #define MATH_FSUM_METHODDEF \ |
| 66 | {"fsum", (PyCFunction)math_fsum, METH_O, math_fsum__doc__}, |
| 67 | |
| 68 | PyDoc_STRVAR(math_factorial__doc__, |
| 69 | "factorial($module, x, /)\n" |
| 70 | "--\n" |
| 71 | "\n" |
| 72 | "Find x!.\n" |
| 73 | "\n" |
| 74 | "Raise a ValueError if x is negative or non-integral."); |
| 75 | |
| 76 | #define MATH_FACTORIAL_METHODDEF \ |
| 77 | {"factorial", (PyCFunction)math_factorial, METH_O, math_factorial__doc__}, |
| 78 | |
| 79 | PyDoc_STRVAR(math_trunc__doc__, |
| 80 | "trunc($module, x, /)\n" |
| 81 | "--\n" |
| 82 | "\n" |
| 83 | "Truncates the Real x to the nearest Integral toward 0.\n" |
| 84 | "\n" |
| 85 | "Uses the __trunc__ magic method."); |
| 86 | |
| 87 | #define MATH_TRUNC_METHODDEF \ |
| 88 | {"trunc", (PyCFunction)math_trunc, METH_O, math_trunc__doc__}, |
| 89 | |
| 90 | PyDoc_STRVAR(math_frexp__doc__, |
| 91 | "frexp($module, x, /)\n" |
| 92 | "--\n" |
| 93 | "\n" |
| 94 | "Return the mantissa and exponent of x, as pair (m, e).\n" |
| 95 | "\n" |
| 96 | "m is a float and e is an int, such that x = m * 2.**e.\n" |
| 97 | "If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0."); |
| 98 | |
| 99 | #define MATH_FREXP_METHODDEF \ |
| 100 | {"frexp", (PyCFunction)math_frexp, METH_O, math_frexp__doc__}, |
| 101 | |
| 102 | static PyObject * |
| 103 | math_frexp_impl(PyObject *module, double x); |
| 104 | |
| 105 | static PyObject * |
| 106 | math_frexp(PyObject *module, PyObject *arg) |
| 107 | { |
| 108 | PyObject *return_value = NULL; |
| 109 | double x; |
| 110 | |
| 111 | if (!PyArg_Parse(arg, "d:frexp", &x)) { |
| 112 | goto exit; |
| 113 | } |
| 114 | return_value = math_frexp_impl(module, x); |
| 115 | |
| 116 | exit: |
| 117 | return return_value; |
| 118 | } |
| 119 | |
| 120 | PyDoc_STRVAR(math_ldexp__doc__, |
| 121 | "ldexp($module, x, i, /)\n" |
| 122 | "--\n" |
| 123 | "\n" |
| 124 | "Return x * (2**i).\n" |
| 125 | "\n" |
| 126 | "This is essentially the inverse of frexp()."); |
| 127 | |
| 128 | #define MATH_LDEXP_METHODDEF \ |
| 129 | {"ldexp", (PyCFunction)math_ldexp, METH_FASTCALL, math_ldexp__doc__}, |
| 130 | |
| 131 | static PyObject * |
| 132 | math_ldexp_impl(PyObject *module, double x, PyObject *i); |
| 133 | |
| 134 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 135 | math_ldexp(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 136 | { |
| 137 | PyObject *return_value = NULL; |
| 138 | double x; |
| 139 | PyObject *i; |
| 140 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 141 | if (!_PyArg_ParseStack(args, nargs, "dO:ldexp", |
| 142 | &x, &i)) { |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 143 | goto exit; |
| 144 | } |
| 145 | return_value = math_ldexp_impl(module, x, i); |
| 146 | |
| 147 | exit: |
| 148 | return return_value; |
| 149 | } |
| 150 | |
| 151 | PyDoc_STRVAR(math_modf__doc__, |
| 152 | "modf($module, x, /)\n" |
| 153 | "--\n" |
| 154 | "\n" |
| 155 | "Return the fractional and integer parts of x.\n" |
| 156 | "\n" |
| 157 | "Both results carry the sign of x and are floats."); |
| 158 | |
| 159 | #define MATH_MODF_METHODDEF \ |
| 160 | {"modf", (PyCFunction)math_modf, METH_O, math_modf__doc__}, |
| 161 | |
| 162 | static PyObject * |
| 163 | math_modf_impl(PyObject *module, double x); |
| 164 | |
| 165 | static PyObject * |
| 166 | math_modf(PyObject *module, PyObject *arg) |
| 167 | { |
| 168 | PyObject *return_value = NULL; |
| 169 | double x; |
| 170 | |
| 171 | if (!PyArg_Parse(arg, "d:modf", &x)) { |
| 172 | goto exit; |
| 173 | } |
| 174 | return_value = math_modf_impl(module, x); |
| 175 | |
| 176 | exit: |
| 177 | return return_value; |
| 178 | } |
| 179 | |
| 180 | PyDoc_STRVAR(math_log__doc__, |
| 181 | "log(x, [base=math.e])\n" |
| 182 | "Return the logarithm of x to the given base.\n" |
| 183 | "\n" |
| 184 | "If the base not specified, returns the natural logarithm (base e) of x."); |
| 185 | |
| 186 | #define MATH_LOG_METHODDEF \ |
| 187 | {"log", (PyCFunction)math_log, METH_VARARGS, math_log__doc__}, |
| 188 | |
| 189 | static PyObject * |
| 190 | math_log_impl(PyObject *module, PyObject *x, int group_right_1, |
| 191 | PyObject *base); |
| 192 | |
| 193 | static PyObject * |
| 194 | math_log(PyObject *module, PyObject *args) |
| 195 | { |
| 196 | PyObject *return_value = NULL; |
| 197 | PyObject *x; |
| 198 | int group_right_1 = 0; |
| 199 | PyObject *base = NULL; |
| 200 | |
| 201 | switch (PyTuple_GET_SIZE(args)) { |
| 202 | case 1: |
| 203 | if (!PyArg_ParseTuple(args, "O:log", &x)) { |
| 204 | goto exit; |
| 205 | } |
| 206 | break; |
| 207 | case 2: |
| 208 | if (!PyArg_ParseTuple(args, "OO:log", &x, &base)) { |
| 209 | goto exit; |
| 210 | } |
| 211 | group_right_1 = 1; |
| 212 | break; |
| 213 | default: |
| 214 | PyErr_SetString(PyExc_TypeError, "math.log requires 1 to 2 arguments"); |
| 215 | goto exit; |
| 216 | } |
| 217 | return_value = math_log_impl(module, x, group_right_1, base); |
| 218 | |
| 219 | exit: |
| 220 | return return_value; |
| 221 | } |
| 222 | |
| 223 | PyDoc_STRVAR(math_log2__doc__, |
| 224 | "log2($module, x, /)\n" |
| 225 | "--\n" |
| 226 | "\n" |
| 227 | "Return the base 2 logarithm of x."); |
| 228 | |
| 229 | #define MATH_LOG2_METHODDEF \ |
| 230 | {"log2", (PyCFunction)math_log2, METH_O, math_log2__doc__}, |
| 231 | |
| 232 | PyDoc_STRVAR(math_log10__doc__, |
| 233 | "log10($module, x, /)\n" |
| 234 | "--\n" |
| 235 | "\n" |
| 236 | "Return the base 10 logarithm of x."); |
| 237 | |
| 238 | #define MATH_LOG10_METHODDEF \ |
| 239 | {"log10", (PyCFunction)math_log10, METH_O, math_log10__doc__}, |
| 240 | |
| 241 | PyDoc_STRVAR(math_fmod__doc__, |
| 242 | "fmod($module, x, y, /)\n" |
| 243 | "--\n" |
| 244 | "\n" |
| 245 | "Return fmod(x, y), according to platform C.\n" |
| 246 | "\n" |
| 247 | "x % y may differ."); |
| 248 | |
| 249 | #define MATH_FMOD_METHODDEF \ |
| 250 | {"fmod", (PyCFunction)math_fmod, METH_FASTCALL, math_fmod__doc__}, |
| 251 | |
| 252 | static PyObject * |
| 253 | math_fmod_impl(PyObject *module, double x, double y); |
| 254 | |
| 255 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 256 | math_fmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 257 | { |
| 258 | PyObject *return_value = NULL; |
| 259 | double x; |
| 260 | double y; |
| 261 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 262 | if (!_PyArg_ParseStack(args, nargs, "dd:fmod", |
| 263 | &x, &y)) { |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 264 | goto exit; |
| 265 | } |
| 266 | return_value = math_fmod_impl(module, x, y); |
| 267 | |
| 268 | exit: |
| 269 | return return_value; |
| 270 | } |
| 271 | |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 272 | PyDoc_STRVAR(math_pow__doc__, |
| 273 | "pow($module, x, y, /)\n" |
| 274 | "--\n" |
| 275 | "\n" |
| 276 | "Return x**y (x to the power of y)."); |
| 277 | |
| 278 | #define MATH_POW_METHODDEF \ |
| 279 | {"pow", (PyCFunction)math_pow, METH_FASTCALL, math_pow__doc__}, |
| 280 | |
| 281 | static PyObject * |
| 282 | math_pow_impl(PyObject *module, double x, double y); |
| 283 | |
| 284 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 285 | math_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs) |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 286 | { |
| 287 | PyObject *return_value = NULL; |
| 288 | double x; |
| 289 | double y; |
| 290 | |
Sylvain | 7445381 | 2017-06-10 06:51:48 +0200 | [diff] [blame] | 291 | if (!_PyArg_ParseStack(args, nargs, "dd:pow", |
| 292 | &x, &y)) { |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 293 | goto exit; |
| 294 | } |
| 295 | return_value = math_pow_impl(module, x, y); |
| 296 | |
| 297 | exit: |
| 298 | return return_value; |
| 299 | } |
| 300 | |
| 301 | PyDoc_STRVAR(math_degrees__doc__, |
| 302 | "degrees($module, x, /)\n" |
| 303 | "--\n" |
| 304 | "\n" |
| 305 | "Convert angle x from radians to degrees."); |
| 306 | |
| 307 | #define MATH_DEGREES_METHODDEF \ |
| 308 | {"degrees", (PyCFunction)math_degrees, METH_O, math_degrees__doc__}, |
| 309 | |
| 310 | static PyObject * |
| 311 | math_degrees_impl(PyObject *module, double x); |
| 312 | |
| 313 | static PyObject * |
| 314 | math_degrees(PyObject *module, PyObject *arg) |
| 315 | { |
| 316 | PyObject *return_value = NULL; |
| 317 | double x; |
| 318 | |
| 319 | if (!PyArg_Parse(arg, "d:degrees", &x)) { |
| 320 | goto exit; |
| 321 | } |
| 322 | return_value = math_degrees_impl(module, x); |
| 323 | |
| 324 | exit: |
| 325 | return return_value; |
| 326 | } |
| 327 | |
| 328 | PyDoc_STRVAR(math_radians__doc__, |
| 329 | "radians($module, x, /)\n" |
| 330 | "--\n" |
| 331 | "\n" |
| 332 | "Convert angle x from degrees to radians."); |
| 333 | |
| 334 | #define MATH_RADIANS_METHODDEF \ |
| 335 | {"radians", (PyCFunction)math_radians, METH_O, math_radians__doc__}, |
| 336 | |
| 337 | static PyObject * |
| 338 | math_radians_impl(PyObject *module, double x); |
| 339 | |
| 340 | static PyObject * |
| 341 | math_radians(PyObject *module, PyObject *arg) |
| 342 | { |
| 343 | PyObject *return_value = NULL; |
| 344 | double x; |
| 345 | |
| 346 | if (!PyArg_Parse(arg, "d:radians", &x)) { |
| 347 | goto exit; |
| 348 | } |
| 349 | return_value = math_radians_impl(module, x); |
| 350 | |
| 351 | exit: |
| 352 | return return_value; |
| 353 | } |
| 354 | |
| 355 | PyDoc_STRVAR(math_isfinite__doc__, |
| 356 | "isfinite($module, x, /)\n" |
| 357 | "--\n" |
| 358 | "\n" |
| 359 | "Return True if x is neither an infinity nor a NaN, and False otherwise."); |
| 360 | |
| 361 | #define MATH_ISFINITE_METHODDEF \ |
| 362 | {"isfinite", (PyCFunction)math_isfinite, METH_O, math_isfinite__doc__}, |
| 363 | |
| 364 | static PyObject * |
| 365 | math_isfinite_impl(PyObject *module, double x); |
| 366 | |
| 367 | static PyObject * |
| 368 | math_isfinite(PyObject *module, PyObject *arg) |
| 369 | { |
| 370 | PyObject *return_value = NULL; |
| 371 | double x; |
| 372 | |
| 373 | if (!PyArg_Parse(arg, "d:isfinite", &x)) { |
| 374 | goto exit; |
| 375 | } |
| 376 | return_value = math_isfinite_impl(module, x); |
| 377 | |
| 378 | exit: |
| 379 | return return_value; |
| 380 | } |
| 381 | |
| 382 | PyDoc_STRVAR(math_isnan__doc__, |
| 383 | "isnan($module, x, /)\n" |
| 384 | "--\n" |
| 385 | "\n" |
| 386 | "Return True if x is a NaN (not a number), and False otherwise."); |
| 387 | |
| 388 | #define MATH_ISNAN_METHODDEF \ |
| 389 | {"isnan", (PyCFunction)math_isnan, METH_O, math_isnan__doc__}, |
| 390 | |
| 391 | static PyObject * |
| 392 | math_isnan_impl(PyObject *module, double x); |
| 393 | |
| 394 | static PyObject * |
| 395 | math_isnan(PyObject *module, PyObject *arg) |
| 396 | { |
| 397 | PyObject *return_value = NULL; |
| 398 | double x; |
| 399 | |
| 400 | if (!PyArg_Parse(arg, "d:isnan", &x)) { |
| 401 | goto exit; |
| 402 | } |
| 403 | return_value = math_isnan_impl(module, x); |
| 404 | |
| 405 | exit: |
| 406 | return return_value; |
| 407 | } |
| 408 | |
| 409 | PyDoc_STRVAR(math_isinf__doc__, |
| 410 | "isinf($module, x, /)\n" |
| 411 | "--\n" |
| 412 | "\n" |
| 413 | "Return True if x is a positive or negative infinity, and False otherwise."); |
| 414 | |
| 415 | #define MATH_ISINF_METHODDEF \ |
| 416 | {"isinf", (PyCFunction)math_isinf, METH_O, math_isinf__doc__}, |
| 417 | |
| 418 | static PyObject * |
| 419 | math_isinf_impl(PyObject *module, double x); |
| 420 | |
| 421 | static PyObject * |
| 422 | math_isinf(PyObject *module, PyObject *arg) |
| 423 | { |
| 424 | PyObject *return_value = NULL; |
| 425 | double x; |
| 426 | |
| 427 | if (!PyArg_Parse(arg, "d:isinf", &x)) { |
| 428 | goto exit; |
| 429 | } |
| 430 | return_value = math_isinf_impl(module, x); |
| 431 | |
| 432 | exit: |
| 433 | return return_value; |
| 434 | } |
| 435 | |
| 436 | PyDoc_STRVAR(math_isclose__doc__, |
| 437 | "isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n" |
| 438 | "--\n" |
| 439 | "\n" |
| 440 | "Determine whether two floating point numbers are close in value.\n" |
| 441 | "\n" |
| 442 | " rel_tol\n" |
| 443 | " maximum difference for being considered \"close\", relative to the\n" |
| 444 | " magnitude of the input values\n" |
| 445 | " abs_tol\n" |
| 446 | " maximum difference for being considered \"close\", regardless of the\n" |
| 447 | " magnitude of the input values\n" |
| 448 | "\n" |
| 449 | "Return True if a is close in value to b, and False otherwise.\n" |
| 450 | "\n" |
| 451 | "For the values to be considered close, the difference between them\n" |
| 452 | "must be smaller than at least one of the tolerances.\n" |
| 453 | "\n" |
| 454 | "-inf, inf and NaN behave similarly to the IEEE 754 Standard. That\n" |
| 455 | "is, NaN is not close to anything, even itself. inf and -inf are\n" |
| 456 | "only close to themselves."); |
| 457 | |
| 458 | #define MATH_ISCLOSE_METHODDEF \ |
Serhiy Storchaka | 6969eaf | 2017-07-03 21:20:15 +0300 | [diff] [blame] | 459 | {"isclose", (PyCFunction)math_isclose, METH_FASTCALL|METH_KEYWORDS, math_isclose__doc__}, |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 460 | |
| 461 | static int |
| 462 | math_isclose_impl(PyObject *module, double a, double b, double rel_tol, |
| 463 | double abs_tol); |
| 464 | |
| 465 | static PyObject * |
Serhiy Storchaka | a5552f0 | 2017-12-15 13:11:11 +0200 | [diff] [blame] | 466 | math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
Serhiy Storchaka | c9ea933 | 2017-01-19 18:13:09 +0200 | [diff] [blame] | 467 | { |
| 468 | PyObject *return_value = NULL; |
| 469 | static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL}; |
| 470 | static _PyArg_Parser _parser = {"dd|$dd:isclose", _keywords, 0}; |
| 471 | double a; |
| 472 | double b; |
| 473 | double rel_tol = 1e-09; |
| 474 | double abs_tol = 0.0; |
| 475 | int _return_value; |
| 476 | |
| 477 | if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser, |
| 478 | &a, &b, &rel_tol, &abs_tol)) { |
| 479 | goto exit; |
| 480 | } |
| 481 | _return_value = math_isclose_impl(module, a, b, rel_tol, abs_tol); |
| 482 | if ((_return_value == -1) && PyErr_Occurred()) { |
| 483 | goto exit; |
| 484 | } |
| 485 | return_value = PyBool_FromLong((long)_return_value); |
| 486 | |
| 487 | exit: |
| 488 | return return_value; |
| 489 | } |
Raymond Hettinger | c6dabe3 | 2018-07-28 07:48:04 -0700 | [diff] [blame] | 490 | /*[clinic end generated code: output=1c35516a10443902 input=a9049054013a1b77]*/ |