Skip to content

Adding math.dist()? #9505

@FoamyGuy

Description

@FoamyGuy

I wondering if there is interest in having an math.dist() (CPython ref: https://docs.python.org/3/library/math.html#math.dist) in the core?

I had a try at implementing it in this branch: https://github.com/FoamyGuy/circuitpython/tree/math_dist. It only supports 2D, whereas the CPython one seems to allow higher dimensions, and I have done only some minimal "happy path" testing, but it does seem to work correctly and mostly match CPython results with the points I've tested.

I started with this issue instead of opening a PR directly because I was unsure of the following:

  1. to gauge whether there is interest in this and

  2. if so to ask if the way that I did it (adding the new implementation into shared-bindings/math/__init__.c) The math module doesn't seem to exist in shared-module most of the functions appear to just map directly to C functions pretty closely, the few that do have additional code are inside of shared-bindings/math/__init__.c so I followed that.

  3. Should this be part of the MICROPY_PY_MATH_SPECIAL_FUNCTIONS? I did put it inside of the if blocks currently. My thought was to try to limit it to not be included on any devices that might be especially tight on firmware space, but I don't know if this flag is actually used for that purpose for certain.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions