[2.7] bpo-11566: Extension build errors on Windows for _hypot by thewtex · Pull Request #880 · python/cpython (original) (raw)

@rgommers Thanks for the pointer.

I was able to find the NumPy _MSC_VER check:

https://github.com/numpy/numpy/blob/8d01ee40eb00160068cce3cb02c930cebf013230/numpy/core/src/private/npy_config.h#L36

and a discrepancy between the NumPy backup implementation and the CPython one:

https://github.com/numpy/numpy/blob/8d01ee40eb00160068cce3cb02c930cebf013230/numpy/core/src/npymath/npy_math_internal.h.src#L196-L202

double hypot(double x, double y)

but the existing MSVC hypot is used prior to this patch and is still used by this patch. It passes tests:

def testHypot(self):
self.assertRaises(TypeError, math.hypot)
self.ftest('hypot(0,0)', math.hypot(0,0), 0)
self.ftest('hypot(3,4)', math.hypot(3,4), 5)
self.assertEqual(math.hypot(NAN, INF), INF)
self.assertEqual(math.hypot(INF, NAN), INF)
self.assertEqual(math.hypot(NAN, NINF), INF)
self.assertEqual(math.hypot(NINF, NAN), INF)
self.assertRaises(OverflowError, math.hypot, FLOAT_MAX, FLOAT_MAX)
self.assertTrue(math.isnan(math.hypot(1.0, NAN)))
self.assertTrue(math.isnan(math.hypot(NAN, -2.0)))

When looking into replacing it, does not looks trivial -- Py_INFINITY needs to be defined. We would have to namespace the name to not conflict with hypot from math.h, ... Since that seems to be a different issue, I would rather just get this one in.

I was able to dig up an old VS 2008 to test this patch.