From 3df127ee1789cf9fb01c1cb98bc98ab6e26d1679 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Fri, 6 Oct 2023 12:15:59 +0300 Subject: [PATCH] More efficient (for finite x) handling of special cases in math.modf Rewrite changes in #102523 --- Modules/mathmodule.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 1b888948ce0ad7..2736d6114510a4 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -2190,10 +2190,12 @@ math_modf_impl(PyObject *module, double x) double y; /* some platforms don't do the right thing for NaNs and infinities, so we take care of special cases directly. */ - if (Py_IS_INFINITY(x)) - return Py_BuildValue("(dd)", copysign(0., x), x); - else if (Py_IS_NAN(x)) - return Py_BuildValue("(dd)", x, x); + if (!Py_IS_FINITE(x)) { + if (Py_IS_INFINITY(x)) + return Py_BuildValue("(dd)", copysign(0., x), x); + else + return Py_BuildValue("(dd)", x, x); + } errno = 0; x = modf(x, &y);