summaryrefslogtreecommitdiffstats
path: root/Modules/clinic/mathmodule.c.h
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-01-12 01:15:42 (GMT)
committerGitHub <noreply@github.com>2020-01-12 01:15:42 (GMT)
commit100fafcf20e8fc67cd8ef512074f9c0a253cb427 (patch)
tree4908c600f2dcda034e767b7f4e9cf50228f83a1b /Modules/clinic/mathmodule.c.h
parent1b335ae281631a12201fdec29b3c55d97166fc06 (diff)
downloadcpython-100fafcf20e8fc67cd8ef512074f9c0a253cb427.zip
cpython-100fafcf20e8fc67cd8ef512074f9c0a253cb427.tar.gz
cpython-100fafcf20e8fc67cd8ef512074f9c0a253cb427.tar.bz2
bpo-39288: Add math.nextafter(x, y) (GH-17937)
Return the next floating-point value after x towards y.
Diffstat (limited to 'Modules/clinic/mathmodule.c.h')
-rw-r--r--Modules/clinic/mathmodule.c.h50
1 files changed, 49 insertions, 1 deletions
diff --git a/Modules/clinic/mathmodule.c.h b/Modules/clinic/mathmodule.c.h
index 95d68ee..f34633c 100644
--- a/Modules/clinic/mathmodule.c.h
+++ b/Modules/clinic/mathmodule.c.h
@@ -808,4 +808,52 @@ math_comb(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return return_value;
}
-/*[clinic end generated code: output=9a2b3dc91eb9aadd input=a9049054013a1b77]*/
+
+PyDoc_STRVAR(math_nextafter__doc__,
+"nextafter($module, x, y, /)\n"
+"--\n"
+"\n"
+"Return the next floating-point value after x towards y.");
+
+#define MATH_NEXTAFTER_METHODDEF \
+ {"nextafter", (PyCFunction)(void(*)(void))math_nextafter, METH_FASTCALL, math_nextafter__doc__},
+
+static PyObject *
+math_nextafter_impl(PyObject *module, double x, double y);
+
+static PyObject *
+math_nextafter(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
+{
+ PyObject *return_value = NULL;
+ double x;
+ double y;
+
+ if (!_PyArg_CheckPositional("nextafter", nargs, 2, 2)) {
+ goto exit;
+ }
+ if (PyFloat_CheckExact(args[0])) {
+ x = PyFloat_AS_DOUBLE(args[0]);
+ }
+ else
+ {
+ x = PyFloat_AsDouble(args[0]);
+ if (x == -1.0 && PyErr_Occurred()) {
+ goto exit;
+ }
+ }
+ if (PyFloat_CheckExact(args[1])) {
+ y = PyFloat_AS_DOUBLE(args[1]);
+ }
+ else
+ {
+ y = PyFloat_AsDouble(args[1]);
+ if (y == -1.0 && PyErr_Occurred()) {
+ goto exit;
+ }
+ }
+ return_value = math_nextafter_impl(module, x, y);
+
+exit:
+ return return_value;
+}
+/*[clinic end generated code: output=e4ed1a800e4b2eae input=a9049054013a1b77]*/