Line data Source code
1 : /*[clinic input]
2 : preserve
3 : [clinic start generated code]*/
4 :
5 : PyDoc_STRVAR(math_ceil__doc__,
6 : "ceil($module, x, /)\n"
7 : "--\n"
8 : "\n"
9 : "Return the ceiling of x as an Integral.\n"
10 : "\n"
11 : "This is the smallest integer >= x.");
12 :
13 : #define MATH_CEIL_METHODDEF \
14 : {"ceil", (PyCFunction)math_ceil, METH_O, math_ceil__doc__},
15 :
16 : PyDoc_STRVAR(math_floor__doc__,
17 : "floor($module, x, /)\n"
18 : "--\n"
19 : "\n"
20 : "Return the floor of x as an Integral.\n"
21 : "\n"
22 : "This is the largest integer <= x.");
23 :
24 : #define MATH_FLOOR_METHODDEF \
25 : {"floor", (PyCFunction)math_floor, METH_O, math_floor__doc__},
26 :
27 : PyDoc_STRVAR(math_fsum__doc__,
28 : "fsum($module, seq, /)\n"
29 : "--\n"
30 : "\n"
31 : "Return an accurate floating point sum of values in the iterable seq.\n"
32 : "\n"
33 : "Assumes IEEE-754 floating point arithmetic.");
34 :
35 : #define MATH_FSUM_METHODDEF \
36 : {"fsum", (PyCFunction)math_fsum, METH_O, math_fsum__doc__},
37 :
38 : PyDoc_STRVAR(math_isqrt__doc__,
39 : "isqrt($module, n, /)\n"
40 : "--\n"
41 : "\n"
42 : "Return the integer part of the square root of the input.");
43 :
44 : #define MATH_ISQRT_METHODDEF \
45 : {"isqrt", (PyCFunction)math_isqrt, METH_O, math_isqrt__doc__},
46 :
47 : PyDoc_STRVAR(math_factorial__doc__,
48 : "factorial($module, n, /)\n"
49 : "--\n"
50 : "\n"
51 : "Find n!.\n"
52 : "\n"
53 : "Raise a ValueError if x is negative or non-integral.");
54 :
55 : #define MATH_FACTORIAL_METHODDEF \
56 : {"factorial", (PyCFunction)math_factorial, METH_O, math_factorial__doc__},
57 :
58 : PyDoc_STRVAR(math_trunc__doc__,
59 : "trunc($module, x, /)\n"
60 : "--\n"
61 : "\n"
62 : "Truncates the Real x to the nearest Integral toward 0.\n"
63 : "\n"
64 : "Uses the __trunc__ magic method.");
65 :
66 : #define MATH_TRUNC_METHODDEF \
67 : {"trunc", (PyCFunction)math_trunc, METH_O, math_trunc__doc__},
68 :
69 : PyDoc_STRVAR(math_frexp__doc__,
70 : "frexp($module, x, /)\n"
71 : "--\n"
72 : "\n"
73 : "Return the mantissa and exponent of x, as pair (m, e).\n"
74 : "\n"
75 : "m is a float and e is an int, such that x = m * 2.**e.\n"
76 : "If x is 0, m and e are both 0. Else 0.5 <= abs(m) < 1.0.");
77 :
78 : #define MATH_FREXP_METHODDEF \
79 : {"frexp", (PyCFunction)math_frexp, METH_O, math_frexp__doc__},
80 :
81 : static PyObject *
82 : math_frexp_impl(PyObject *module, double x);
83 :
84 : static PyObject *
85 523934 : math_frexp(PyObject *module, PyObject *arg)
86 : {
87 523934 : PyObject *return_value = NULL;
88 : double x;
89 :
90 523934 : if (PyFloat_CheckExact(arg)) {
91 483834 : x = PyFloat_AS_DOUBLE(arg);
92 : }
93 : else
94 : {
95 40100 : x = PyFloat_AsDouble(arg);
96 40100 : if (x == -1.0 && PyErr_Occurred()) {
97 0 : goto exit;
98 : }
99 : }
100 523934 : return_value = math_frexp_impl(module, x);
101 :
102 523934 : exit:
103 523934 : return return_value;
104 : }
105 :
106 : PyDoc_STRVAR(math_ldexp__doc__,
107 : "ldexp($module, x, i, /)\n"
108 : "--\n"
109 : "\n"
110 : "Return x * (2**i).\n"
111 : "\n"
112 : "This is essentially the inverse of frexp().");
113 :
114 : #define MATH_LDEXP_METHODDEF \
115 : {"ldexp", _PyCFunction_CAST(math_ldexp), METH_FASTCALL, math_ldexp__doc__},
116 :
117 : static PyObject *
118 : math_ldexp_impl(PyObject *module, double x, PyObject *i);
119 :
120 : static PyObject *
121 597509 : math_ldexp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
122 : {
123 597509 : PyObject *return_value = NULL;
124 : double x;
125 : PyObject *i;
126 :
127 597509 : if (!_PyArg_CheckPositional("ldexp", nargs, 2, 2)) {
128 1 : goto exit;
129 : }
130 597508 : if (PyFloat_CheckExact(args[0])) {
131 544634 : x = PyFloat_AS_DOUBLE(args[0]);
132 : }
133 : else
134 : {
135 52874 : x = PyFloat_AsDouble(args[0]);
136 52874 : if (x == -1.0 && PyErr_Occurred()) {
137 0 : goto exit;
138 : }
139 : }
140 597508 : i = args[1];
141 597508 : return_value = math_ldexp_impl(module, x, i);
142 :
143 597509 : exit:
144 597509 : return return_value;
145 : }
146 :
147 : PyDoc_STRVAR(math_modf__doc__,
148 : "modf($module, x, /)\n"
149 : "--\n"
150 : "\n"
151 : "Return the fractional and integer parts of x.\n"
152 : "\n"
153 : "Both results carry the sign of x and are floats.");
154 :
155 : #define MATH_MODF_METHODDEF \
156 : {"modf", (PyCFunction)math_modf, METH_O, math_modf__doc__},
157 :
158 : static PyObject *
159 : math_modf_impl(PyObject *module, double x);
160 :
161 : static PyObject *
162 3146 : math_modf(PyObject *module, PyObject *arg)
163 : {
164 3146 : PyObject *return_value = NULL;
165 : double x;
166 :
167 3146 : if (PyFloat_CheckExact(arg)) {
168 2461 : x = PyFloat_AS_DOUBLE(arg);
169 : }
170 : else
171 : {
172 685 : x = PyFloat_AsDouble(arg);
173 685 : if (x == -1.0 && PyErr_Occurred()) {
174 0 : goto exit;
175 : }
176 : }
177 3146 : return_value = math_modf_impl(module, x);
178 :
179 3146 : exit:
180 3146 : return return_value;
181 : }
182 :
183 : PyDoc_STRVAR(math_log__doc__,
184 : "log(x, [base=math.e])\n"
185 : "Return the logarithm of x to the given base.\n"
186 : "\n"
187 : "If the base not specified, returns the natural logarithm (base e) of x.");
188 :
189 : #define MATH_LOG_METHODDEF \
190 : {"log", (PyCFunction)math_log, METH_VARARGS, math_log__doc__},
191 :
192 : static PyObject *
193 : math_log_impl(PyObject *module, PyObject *x, int group_right_1,
194 : PyObject *base);
195 :
196 : static PyObject *
197 597994 : math_log(PyObject *module, PyObject *args)
198 : {
199 597994 : PyObject *return_value = NULL;
200 : PyObject *x;
201 597994 : int group_right_1 = 0;
202 597994 : PyObject *base = NULL;
203 :
204 597994 : switch (PyTuple_GET_SIZE(args)) {
205 591092 : case 1:
206 591092 : if (!PyArg_ParseTuple(args, "O:log", &x)) {
207 0 : goto exit;
208 : }
209 591092 : break;
210 6901 : case 2:
211 6901 : if (!PyArg_ParseTuple(args, "OO:log", &x, &base)) {
212 0 : goto exit;
213 : }
214 6901 : group_right_1 = 1;
215 6901 : break;
216 1 : default:
217 1 : PyErr_SetString(PyExc_TypeError, "math.log requires 1 to 2 arguments");
218 1 : goto exit;
219 : }
220 597993 : return_value = math_log_impl(module, x, group_right_1, base);
221 :
222 597994 : exit:
223 597994 : return return_value;
224 : }
225 :
226 : PyDoc_STRVAR(math_log2__doc__,
227 : "log2($module, x, /)\n"
228 : "--\n"
229 : "\n"
230 : "Return the base 2 logarithm of x.");
231 :
232 : #define MATH_LOG2_METHODDEF \
233 : {"log2", (PyCFunction)math_log2, METH_O, math_log2__doc__},
234 :
235 : PyDoc_STRVAR(math_log10__doc__,
236 : "log10($module, x, /)\n"
237 : "--\n"
238 : "\n"
239 : "Return the base 10 logarithm of x.");
240 :
241 : #define MATH_LOG10_METHODDEF \
242 : {"log10", (PyCFunction)math_log10, METH_O, math_log10__doc__},
243 :
244 : PyDoc_STRVAR(math_fmod__doc__,
245 : "fmod($module, x, y, /)\n"
246 : "--\n"
247 : "\n"
248 : "Return fmod(x, y), according to platform C.\n"
249 : "\n"
250 : "x % y may differ.");
251 :
252 : #define MATH_FMOD_METHODDEF \
253 : {"fmod", _PyCFunction_CAST(math_fmod), METH_FASTCALL, math_fmod__doc__},
254 :
255 : static PyObject *
256 : math_fmod_impl(PyObject *module, double x, double y);
257 :
258 : static PyObject *
259 20 : math_fmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
260 : {
261 20 : PyObject *return_value = NULL;
262 : double x;
263 : double y;
264 :
265 20 : if (!_PyArg_CheckPositional("fmod", nargs, 2, 2)) {
266 1 : goto exit;
267 : }
268 19 : if (PyFloat_CheckExact(args[0])) {
269 13 : x = PyFloat_AS_DOUBLE(args[0]);
270 : }
271 : else
272 : {
273 6 : x = PyFloat_AsDouble(args[0]);
274 6 : if (x == -1.0 && PyErr_Occurred()) {
275 0 : goto exit;
276 : }
277 : }
278 19 : if (PyFloat_CheckExact(args[1])) {
279 17 : y = PyFloat_AS_DOUBLE(args[1]);
280 : }
281 : else
282 : {
283 2 : y = PyFloat_AsDouble(args[1]);
284 2 : if (y == -1.0 && PyErr_Occurred()) {
285 0 : goto exit;
286 : }
287 : }
288 19 : return_value = math_fmod_impl(module, x, y);
289 :
290 20 : exit:
291 20 : return return_value;
292 : }
293 :
294 : PyDoc_STRVAR(math_dist__doc__,
295 : "dist($module, p, q, /)\n"
296 : "--\n"
297 : "\n"
298 : "Return the Euclidean distance between two points p and q.\n"
299 : "\n"
300 : "The points should be specified as sequences (or iterables) of\n"
301 : "coordinates. Both inputs must have the same dimension.\n"
302 : "\n"
303 : "Roughly equivalent to:\n"
304 : " sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))");
305 :
306 : #define MATH_DIST_METHODDEF \
307 : {"dist", _PyCFunction_CAST(math_dist), METH_FASTCALL, math_dist__doc__},
308 :
309 : static PyObject *
310 : math_dist_impl(PyObject *module, PyObject *p, PyObject *q);
311 :
312 : static PyObject *
313 113771 : math_dist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
314 : {
315 113771 : PyObject *return_value = NULL;
316 : PyObject *p;
317 : PyObject *q;
318 :
319 113771 : if (!_PyArg_CheckPositional("dist", nargs, 2, 2)) {
320 2 : goto exit;
321 : }
322 113769 : p = args[0];
323 113769 : q = args[1];
324 113769 : return_value = math_dist_impl(module, p, q);
325 :
326 113771 : exit:
327 113771 : return return_value;
328 : }
329 :
330 : PyDoc_STRVAR(math_pow__doc__,
331 : "pow($module, x, y, /)\n"
332 : "--\n"
333 : "\n"
334 : "Return x**y (x to the power of y).");
335 :
336 : #define MATH_POW_METHODDEF \
337 : {"pow", _PyCFunction_CAST(math_pow), METH_FASTCALL, math_pow__doc__},
338 :
339 : static PyObject *
340 : math_pow_impl(PyObject *module, double x, double y);
341 :
342 : static PyObject *
343 121 : math_pow(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
344 : {
345 121 : PyObject *return_value = NULL;
346 : double x;
347 : double y;
348 :
349 121 : if (!_PyArg_CheckPositional("pow", nargs, 2, 2)) {
350 1 : goto exit;
351 : }
352 120 : if (PyFloat_CheckExact(args[0])) {
353 103 : x = PyFloat_AS_DOUBLE(args[0]);
354 : }
355 : else
356 : {
357 17 : x = PyFloat_AsDouble(args[0]);
358 17 : if (x == -1.0 && PyErr_Occurred()) {
359 0 : goto exit;
360 : }
361 : }
362 120 : if (PyFloat_CheckExact(args[1])) {
363 111 : y = PyFloat_AS_DOUBLE(args[1]);
364 : }
365 : else
366 : {
367 9 : y = PyFloat_AsDouble(args[1]);
368 9 : if (y == -1.0 && PyErr_Occurred()) {
369 0 : goto exit;
370 : }
371 : }
372 120 : return_value = math_pow_impl(module, x, y);
373 :
374 121 : exit:
375 121 : return return_value;
376 : }
377 :
378 : PyDoc_STRVAR(math_degrees__doc__,
379 : "degrees($module, x, /)\n"
380 : "--\n"
381 : "\n"
382 : "Convert angle x from radians to degrees.");
383 :
384 : #define MATH_DEGREES_METHODDEF \
385 : {"degrees", (PyCFunction)math_degrees, METH_O, math_degrees__doc__},
386 :
387 : static PyObject *
388 : math_degrees_impl(PyObject *module, double x);
389 :
390 : static PyObject *
391 56 : math_degrees(PyObject *module, PyObject *arg)
392 : {
393 56 : PyObject *return_value = NULL;
394 : double x;
395 :
396 56 : if (PyFloat_CheckExact(arg)) {
397 55 : x = PyFloat_AS_DOUBLE(arg);
398 : }
399 : else
400 : {
401 1 : x = PyFloat_AsDouble(arg);
402 1 : if (x == -1.0 && PyErr_Occurred()) {
403 0 : goto exit;
404 : }
405 : }
406 56 : return_value = math_degrees_impl(module, x);
407 :
408 56 : exit:
409 56 : return return_value;
410 : }
411 :
412 : PyDoc_STRVAR(math_radians__doc__,
413 : "radians($module, x, /)\n"
414 : "--\n"
415 : "\n"
416 : "Convert angle x from degrees to radians.");
417 :
418 : #define MATH_RADIANS_METHODDEF \
419 : {"radians", (PyCFunction)math_radians, METH_O, math_radians__doc__},
420 :
421 : static PyObject *
422 : math_radians_impl(PyObject *module, double x);
423 :
424 : static PyObject *
425 43 : math_radians(PyObject *module, PyObject *arg)
426 : {
427 43 : PyObject *return_value = NULL;
428 : double x;
429 :
430 43 : if (PyFloat_CheckExact(arg)) {
431 34 : x = PyFloat_AS_DOUBLE(arg);
432 : }
433 : else
434 : {
435 9 : x = PyFloat_AsDouble(arg);
436 9 : if (x == -1.0 && PyErr_Occurred()) {
437 0 : goto exit;
438 : }
439 : }
440 43 : return_value = math_radians_impl(module, x);
441 :
442 43 : exit:
443 43 : return return_value;
444 : }
445 :
446 : PyDoc_STRVAR(math_isfinite__doc__,
447 : "isfinite($module, x, /)\n"
448 : "--\n"
449 : "\n"
450 : "Return True if x is neither an infinity nor a NaN, and False otherwise.");
451 :
452 : #define MATH_ISFINITE_METHODDEF \
453 : {"isfinite", (PyCFunction)math_isfinite, METH_O, math_isfinite__doc__},
454 :
455 : static PyObject *
456 : math_isfinite_impl(PyObject *module, double x);
457 :
458 : static PyObject *
459 163 : math_isfinite(PyObject *module, PyObject *arg)
460 : {
461 163 : PyObject *return_value = NULL;
462 : double x;
463 :
464 163 : if (PyFloat_CheckExact(arg)) {
465 158 : x = PyFloat_AS_DOUBLE(arg);
466 : }
467 : else
468 : {
469 5 : x = PyFloat_AsDouble(arg);
470 5 : if (x == -1.0 && PyErr_Occurred()) {
471 0 : goto exit;
472 : }
473 : }
474 163 : return_value = math_isfinite_impl(module, x);
475 :
476 163 : exit:
477 163 : return return_value;
478 : }
479 :
480 : PyDoc_STRVAR(math_isnan__doc__,
481 : "isnan($module, x, /)\n"
482 : "--\n"
483 : "\n"
484 : "Return True if x is a NaN (not a number), and False otherwise.");
485 :
486 : #define MATH_ISNAN_METHODDEF \
487 : {"isnan", (PyCFunction)math_isnan, METH_O, math_isnan__doc__},
488 :
489 : static PyObject *
490 : math_isnan_impl(PyObject *module, double x);
491 :
492 : static PyObject *
493 111353 : math_isnan(PyObject *module, PyObject *arg)
494 : {
495 111353 : PyObject *return_value = NULL;
496 : double x;
497 :
498 111353 : if (PyFloat_CheckExact(arg)) {
499 110035 : x = PyFloat_AS_DOUBLE(arg);
500 : }
501 : else
502 : {
503 1318 : x = PyFloat_AsDouble(arg);
504 1318 : if (x == -1.0 && PyErr_Occurred()) {
505 0 : goto exit;
506 : }
507 : }
508 111353 : return_value = math_isnan_impl(module, x);
509 :
510 111353 : exit:
511 111353 : return return_value;
512 : }
513 :
514 : PyDoc_STRVAR(math_isinf__doc__,
515 : "isinf($module, x, /)\n"
516 : "--\n"
517 : "\n"
518 : "Return True if x is a positive or negative infinity, and False otherwise.");
519 :
520 : #define MATH_ISINF_METHODDEF \
521 : {"isinf", (PyCFunction)math_isinf, METH_O, math_isinf__doc__},
522 :
523 : static PyObject *
524 : math_isinf_impl(PyObject *module, double x);
525 :
526 : static PyObject *
527 247236 : math_isinf(PyObject *module, PyObject *arg)
528 : {
529 247236 : PyObject *return_value = NULL;
530 : double x;
531 :
532 247236 : if (PyFloat_CheckExact(arg)) {
533 246144 : x = PyFloat_AS_DOUBLE(arg);
534 : }
535 : else
536 : {
537 1092 : x = PyFloat_AsDouble(arg);
538 1092 : if (x == -1.0 && PyErr_Occurred()) {
539 0 : goto exit;
540 : }
541 : }
542 247236 : return_value = math_isinf_impl(module, x);
543 :
544 247236 : exit:
545 247236 : return return_value;
546 : }
547 :
548 : PyDoc_STRVAR(math_isclose__doc__,
549 : "isclose($module, /, a, b, *, rel_tol=1e-09, abs_tol=0.0)\n"
550 : "--\n"
551 : "\n"
552 : "Determine whether two floating point numbers are close in value.\n"
553 : "\n"
554 : " rel_tol\n"
555 : " maximum difference for being considered \"close\", relative to the\n"
556 : " magnitude of the input values\n"
557 : " abs_tol\n"
558 : " maximum difference for being considered \"close\", regardless of the\n"
559 : " magnitude of the input values\n"
560 : "\n"
561 : "Return True if a is close in value to b, and False otherwise.\n"
562 : "\n"
563 : "For the values to be considered close, the difference between them\n"
564 : "must be smaller than at least one of the tolerances.\n"
565 : "\n"
566 : "-inf, inf and NaN behave similarly to the IEEE 754 Standard. That\n"
567 : "is, NaN is not close to anything, even itself. inf and -inf are\n"
568 : "only close to themselves.");
569 :
570 : #define MATH_ISCLOSE_METHODDEF \
571 : {"isclose", _PyCFunction_CAST(math_isclose), METH_FASTCALL|METH_KEYWORDS, math_isclose__doc__},
572 :
573 : static int
574 : math_isclose_impl(PyObject *module, double a, double b, double rel_tol,
575 : double abs_tol);
576 :
577 : static PyObject *
578 313 : math_isclose(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
579 : {
580 313 : PyObject *return_value = NULL;
581 : static const char * const _keywords[] = {"a", "b", "rel_tol", "abs_tol", NULL};
582 : static _PyArg_Parser _parser = {NULL, _keywords, "isclose", 0};
583 : PyObject *argsbuf[4];
584 313 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
585 : double a;
586 : double b;
587 313 : double rel_tol = 1e-09;
588 313 : double abs_tol = 0.0;
589 : int _return_value;
590 :
591 313 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
592 313 : if (!args) {
593 0 : goto exit;
594 : }
595 313 : if (PyFloat_CheckExact(args[0])) {
596 289 : a = PyFloat_AS_DOUBLE(args[0]);
597 : }
598 : else
599 : {
600 24 : a = PyFloat_AsDouble(args[0]);
601 24 : if (a == -1.0 && PyErr_Occurred()) {
602 0 : goto exit;
603 : }
604 : }
605 313 : if (PyFloat_CheckExact(args[1])) {
606 290 : b = PyFloat_AS_DOUBLE(args[1]);
607 : }
608 : else
609 : {
610 23 : b = PyFloat_AsDouble(args[1]);
611 23 : if (b == -1.0 && PyErr_Occurred()) {
612 0 : goto exit;
613 : }
614 : }
615 313 : if (!noptargs) {
616 221 : goto skip_optional_kwonly;
617 : }
618 92 : if (args[2]) {
619 65 : if (PyFloat_CheckExact(args[2])) {
620 65 : rel_tol = PyFloat_AS_DOUBLE(args[2]);
621 : }
622 : else
623 : {
624 0 : rel_tol = PyFloat_AsDouble(args[2]);
625 0 : if (rel_tol == -1.0 && PyErr_Occurred()) {
626 0 : goto exit;
627 : }
628 : }
629 65 : if (!--noptargs) {
630 58 : goto skip_optional_kwonly;
631 : }
632 : }
633 34 : if (PyFloat_CheckExact(args[3])) {
634 34 : abs_tol = PyFloat_AS_DOUBLE(args[3]);
635 : }
636 : else
637 : {
638 0 : abs_tol = PyFloat_AsDouble(args[3]);
639 0 : if (abs_tol == -1.0 && PyErr_Occurred()) {
640 0 : goto exit;
641 : }
642 : }
643 0 : skip_optional_kwonly:
644 313 : _return_value = math_isclose_impl(module, a, b, rel_tol, abs_tol);
645 313 : if ((_return_value == -1) && PyErr_Occurred()) {
646 2 : goto exit;
647 : }
648 311 : return_value = PyBool_FromLong((long)_return_value);
649 :
650 313 : exit:
651 313 : return return_value;
652 : }
653 :
654 : PyDoc_STRVAR(math_prod__doc__,
655 : "prod($module, iterable, /, *, start=1)\n"
656 : "--\n"
657 : "\n"
658 : "Calculate the product of all the elements in the input iterable.\n"
659 : "\n"
660 : "The default start value for the product is 1.\n"
661 : "\n"
662 : "When the iterable is empty, return the start value. This function is\n"
663 : "intended specifically for use with numeric values and may reject\n"
664 : "non-numeric types.");
665 :
666 : #define MATH_PROD_METHODDEF \
667 : {"prod", _PyCFunction_CAST(math_prod), METH_FASTCALL|METH_KEYWORDS, math_prod__doc__},
668 :
669 : static PyObject *
670 : math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start);
671 :
672 : static PyObject *
673 62 : math_prod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
674 : {
675 62 : PyObject *return_value = NULL;
676 : static const char * const _keywords[] = {"", "start", NULL};
677 : static _PyArg_Parser _parser = {NULL, _keywords, "prod", 0};
678 : PyObject *argsbuf[2];
679 62 : Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
680 : PyObject *iterable;
681 62 : PyObject *start = NULL;
682 :
683 62 : args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
684 62 : if (!args) {
685 2 : goto exit;
686 : }
687 60 : iterable = args[0];
688 60 : if (!noptargs) {
689 49 : goto skip_optional_kwonly;
690 : }
691 11 : start = args[1];
692 60 : skip_optional_kwonly:
693 60 : return_value = math_prod_impl(module, iterable, start);
694 :
695 62 : exit:
696 62 : return return_value;
697 : }
698 :
699 : PyDoc_STRVAR(math_perm__doc__,
700 : "perm($module, n, k=None, /)\n"
701 : "--\n"
702 : "\n"
703 : "Number of ways to choose k items from n items without repetition and with order.\n"
704 : "\n"
705 : "Evaluates to n! / (n - k)! when k <= n and evaluates\n"
706 : "to zero when k > n.\n"
707 : "\n"
708 : "If k is not specified or is None, then k defaults to n\n"
709 : "and the function returns n!.\n"
710 : "\n"
711 : "Raises TypeError if either of the arguments are not integers.\n"
712 : "Raises ValueError if either of the arguments are negative.");
713 :
714 : #define MATH_PERM_METHODDEF \
715 : {"perm", _PyCFunction_CAST(math_perm), METH_FASTCALL, math_perm__doc__},
716 :
717 : static PyObject *
718 : math_perm_impl(PyObject *module, PyObject *n, PyObject *k);
719 :
720 : static PyObject *
721 25973 : math_perm(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
722 : {
723 25973 : PyObject *return_value = NULL;
724 : PyObject *n;
725 25973 : PyObject *k = Py_None;
726 :
727 25973 : if (!_PyArg_CheckPositional("perm", nargs, 1, 2)) {
728 3 : goto exit;
729 : }
730 25970 : n = args[0];
731 25970 : if (nargs < 2) {
732 20 : goto skip_optional;
733 : }
734 25950 : k = args[1];
735 25970 : skip_optional:
736 25970 : return_value = math_perm_impl(module, n, k);
737 :
738 25973 : exit:
739 25973 : return return_value;
740 : }
741 :
742 : PyDoc_STRVAR(math_comb__doc__,
743 : "comb($module, n, k, /)\n"
744 : "--\n"
745 : "\n"
746 : "Number of ways to choose k items from n items without repetition and without order.\n"
747 : "\n"
748 : "Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates\n"
749 : "to zero when k > n.\n"
750 : "\n"
751 : "Also called the binomial coefficient because it is equivalent\n"
752 : "to the coefficient of k-th term in polynomial expansion of the\n"
753 : "expression (1 + x)**n.\n"
754 : "\n"
755 : "Raises TypeError if either of the arguments are not integers.\n"
756 : "Raises ValueError if either of the arguments are negative.");
757 :
758 : #define MATH_COMB_METHODDEF \
759 : {"comb", _PyCFunction_CAST(math_comb), METH_FASTCALL, math_comb__doc__},
760 :
761 : static PyObject *
762 : math_comb_impl(PyObject *module, PyObject *n, PyObject *k);
763 :
764 : static PyObject *
765 30937 : math_comb(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
766 : {
767 30937 : PyObject *return_value = NULL;
768 : PyObject *n;
769 : PyObject *k;
770 :
771 30937 : if (!_PyArg_CheckPositional("comb", nargs, 2, 2)) {
772 3 : goto exit;
773 : }
774 30934 : n = args[0];
775 30934 : k = args[1];
776 30934 : return_value = math_comb_impl(module, n, k);
777 :
778 30937 : exit:
779 30937 : return return_value;
780 : }
781 :
782 : PyDoc_STRVAR(math_nextafter__doc__,
783 : "nextafter($module, x, y, /)\n"
784 : "--\n"
785 : "\n"
786 : "Return the next floating-point value after x towards y.");
787 :
788 : #define MATH_NEXTAFTER_METHODDEF \
789 : {"nextafter", _PyCFunction_CAST(math_nextafter), METH_FASTCALL, math_nextafter__doc__},
790 :
791 : static PyObject *
792 : math_nextafter_impl(PyObject *module, double x, double y);
793 :
794 : static PyObject *
795 117415 : math_nextafter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
796 : {
797 117415 : PyObject *return_value = NULL;
798 : double x;
799 : double y;
800 :
801 117415 : if (!_PyArg_CheckPositional("nextafter", nargs, 2, 2)) {
802 0 : goto exit;
803 : }
804 117415 : if (PyFloat_CheckExact(args[0])) {
805 117415 : x = PyFloat_AS_DOUBLE(args[0]);
806 : }
807 : else
808 : {
809 0 : x = PyFloat_AsDouble(args[0]);
810 0 : if (x == -1.0 && PyErr_Occurred()) {
811 0 : goto exit;
812 : }
813 : }
814 117415 : if (PyFloat_CheckExact(args[1])) {
815 117415 : y = PyFloat_AS_DOUBLE(args[1]);
816 : }
817 : else
818 : {
819 0 : y = PyFloat_AsDouble(args[1]);
820 0 : if (y == -1.0 && PyErr_Occurred()) {
821 0 : goto exit;
822 : }
823 : }
824 117415 : return_value = math_nextafter_impl(module, x, y);
825 :
826 117415 : exit:
827 117415 : return return_value;
828 : }
829 :
830 : PyDoc_STRVAR(math_ulp__doc__,
831 : "ulp($module, x, /)\n"
832 : "--\n"
833 : "\n"
834 : "Return the value of the least significant bit of the float x.");
835 :
836 : #define MATH_ULP_METHODDEF \
837 : {"ulp", (PyCFunction)math_ulp, METH_O, math_ulp__doc__},
838 :
839 : static double
840 : math_ulp_impl(PyObject *module, double x);
841 :
842 : static PyObject *
843 21 : math_ulp(PyObject *module, PyObject *arg)
844 : {
845 21 : PyObject *return_value = NULL;
846 : double x;
847 : double _return_value;
848 :
849 21 : if (PyFloat_CheckExact(arg)) {
850 11 : x = PyFloat_AS_DOUBLE(arg);
851 : }
852 : else
853 : {
854 10 : x = PyFloat_AsDouble(arg);
855 10 : if (x == -1.0 && PyErr_Occurred()) {
856 0 : goto exit;
857 : }
858 : }
859 21 : _return_value = math_ulp_impl(module, x);
860 21 : if ((_return_value == -1.0) && PyErr_Occurred()) {
861 0 : goto exit;
862 : }
863 21 : return_value = PyFloat_FromDouble(_return_value);
864 :
865 21 : exit:
866 21 : return return_value;
867 : }
868 : /*[clinic end generated code: output=965f99dabaa72165 input=a9049054013a1b77]*/
|