Skip to content

Add missing long double math functions #3570

Description

@p00ya

The libc.math module (cython/Cython/Includes/libc/math.pxd) seems to be missing a bunch of long double functions. For example, this will error:

from libc.math cimport expl

I wasn't sure if that was intentional for portability. There's a workaround to use the numpy.math equivalents (though one may not want a numpy dependency or the non-system implementation). If it's just an oversight, I can send a PR.

Tangentially related: I also considered a new module corresponding to C99's <tgmath.h>, which uses macros that expand into the appropriate function call depending on the type (e.g. exp(x) in C will call expl, exp, cexp or expf depending on the static type of x). If we did:

cdef extern from "<tgmath.h>" nogil:
  long double exp(long double x)

def foo(float x):
  cdef float y
  y = exp(x)

would that end up generating appropriate C to call expf via the macro, or would the Cython declaration cause an upcast to long double? I couldn't find documentation for what assumptions Cython makes about the types relating to extern'd macros.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions