GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge m_atan2() and c_atan2() helper functions (or replace libm's atan2) · Issue #122681 · python/cpython

Merge m_atan2() and c_atan2() helper functions (or replace libm's atan2) #122681

New issue
Copy link
New issue
Copy link
Closed
Closed
Merge m_atan2() and c_atan2() helper functions (or replace libm's atan2)#122681
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@skirpichev
skirpichev
opened on Aug 5, 2024
Issue body actions

Feature or enhancement

Proposal:

With #29179, many workarounds for buggy libm implementations were removed. Yet, there is m_atan2():

cpython/Modules/mathmodule.c

Lines 546 to 572 in d0b92dd

static double
m_atan2(double y, double x)
{
if (isnan(x) || isnan(y))
return Py_NAN;
if (isinf(y)) {
if (isinf(x)) {
if (copysign(1., x) == 1.)
/* atan2(+-inf, +inf) == +-pi/4 */
return copysign(0.25*Py_MATH_PI, y);
else
/* atan2(+-inf, -inf) == +-pi*3/4 */
return copysign(0.75*Py_MATH_PI, y);
}
/* atan2(+-inf, x) == +-pi/2 for finite x */
return copysign(0.5*Py_MATH_PI, y);
}
if (isinf(x) || y == 0.) {
if (copysign(1., x) == 1.)
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
return copysign(0., y);
else
/* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
return copysign(Py_MATH_PI, y);
}
return atan2(y, x);
}

and

cpython/Modules/cmathmodule.c

Lines 329 to 355 in d0b92dd

static double
c_atan2(Py_complex z)
{
if (isnan(z.real) || isnan(z.imag))
return Py_NAN;
if (isinf(z.imag)) {
if (isinf(z.real)) {
if (copysign(1., z.real) == 1.)
/* atan2(+-inf, +inf) == +-pi/4 */
return copysign(0.25*Py_MATH_PI, z.imag);
else
/* atan2(+-inf, -inf) == +-pi*3/4 */
return copysign(0.75*Py_MATH_PI, z.imag);
}
/* atan2(+-inf, x) == +-pi/2 for finite x */
return copysign(0.5*Py_MATH_PI, z.imag);
}
if (isinf(z.real) || z.imag == 0.) {
if (copysign(1., z.real) == 1.)
/* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
return copysign(0., z.imag);
else
/* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
return copysign(Py_MATH_PI, z.imag);
}
return atan2(z.imag, z.real);
}

They are identical, the second one just uses Py_complex to keep arguments.

We should either 1) move first helper to _math.h and reuse it in the cmathmodule.c or 2) just remove these helpers. I'll provide patch for 1) proposal.

But 2) looks also safe for me: it seems that c_atan2() helper was used only for cmath.phase() and cmath.polar(); libm's atan2() used for the rest - and this don't poses any problems in CI or build bots. ("Problem" values are tested, e.g. infinities and nans for acos().)

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-122681: merge m_atan2() and c_atan2() helper functions #122682
  • gh-122681: remove m_atan2()/c_atan2() helpers #122715

Activity

  1. skirpichev
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Aug 5, 2024
  2. skirpichev
    added 2 commits that reference this issue on Aug 5, 2024

    pythongh-122681: merge m_atan2() and c_atan2() helper functions

    dc453f6

    pythongh-122681: remove m_atan2()/c_atan2() helpers

    c096fad
  3. vstinner
    added a commit that references this issue on Aug 6, 2024

    gh-122681: merge m_atan2() and c_atan2() helper functions (#122682)

    0b433aa
  4. brandtbucher
    added a commit that references this issue on Aug 7, 2024

    pythongh-122681: merge m_atan2() and c_atan2() helper functions (pyth…

    bc422ed
  5. kumaraditya303
    added a commit that references this issue on Aug 17, 2024

    gh-122681: remove m_atan2()/c_atan2() helpers (#122715)

    19be0ee
  6. kumaraditya303
    closed this as completedon Aug 17, 2024
  7. jeremyhylton
    added a commit that references this issue on Aug 19, 2024

    pythongh-122681: remove m_atan2()/c_atan2() helpers (python#122715)

    a5f57ab
  8. blhsing
    added 2 commits that reference this issue on Aug 22, 2024

    pythongh-122681: merge m_atan2() and c_atan2() helper functions (pyth…

    094aa0b

    pythongh-122681: remove m_atan2()/c_atan2() helpers (python#122715)

    d7d56eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.