Skip to content

py/modmath: New function math hypot. #8593

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Leah1115
Copy link

Implement the math.hypot function.
This implementation covers the Change in CPython 3.8, Multidimensional support of math.hypot(). python/cpython#8474
This was worked on with the assistance of @wang3450

Copy link
Contributor

@dlech dlech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add this function to docs/library/math.rst too.

And mark the relevant line as Completed in docs/differences/python_38.rst.

ans = (mp_float_t)0.0;
for (size_t i = 0; i < n_args; i++) {
a = mp_obj_get_float(args[i]);
a_pow2 = MICROPY_FLOAT_C_FUN(pow)(a, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more efficient to just do ans += a * a instead of calling pow?

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label Apr 29, 2022
(),
(1.5, 1.5, 0.5),
(1.5, 0.5, 1.5),
),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add tests for NaN and infinity arguments and return values?

@projectgus
Copy link
Contributor

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants