8000 bpo-33089: Multidimensional math.hypot() by rhettinger · Pull Request #8474 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-33089: Multidimensional math.hypot() #8474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jul 28, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Test for failed malloc(). Only test inf at the end.
  • Loading branch information
rhettinger committed Jul 28, 2018
commit ee1374c67e1b2cdb071f6387dbf068ce084daf9d
6 changes: 3 additions & 3 deletions Modules/mathmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2041,11 +2041,12 @@ math_hypot(PyObject *self, PyObject *args)
double max = 0.0;
double csum = 0.0;
double x, result;
int found_inf = 0;
int found_nan = 0;

n = PyTuple_GET_SIZE(args);
coordinates = (double *) PyObject_Malloc(n * sizeof(double));
if (coordinates == NULL)
return NULL;
for (i=0 ; i<n ; i++) {
item = PyTuple_GET_ITEM(args, i);
x = PyFloat_AsDouble(item);
Expand All @@ -2055,13 +2056,12 @@ math_hypot(PyObject *self, PyObject *args)
}
x = fabs(x);
coordinates[i] = x;
found_inf |= Py_IS_INFINITY(x);
found_nan |= Py_IS_NAN(x);
if (x > max) {
max = x;
}
}
if (found_inf) {
if (Py_IS_INFINITY(max)) {
result = max;
goto done;
}
Expand Down
0