Skip to content
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

Access to abs() from C interface #518

Open
deyanmihaylov opened this issue Sep 18, 2024 · 2 comments
Open

Access to abs() from C interface #518

deyanmihaylov opened this issue Sep 18, 2024 · 2 comments

Comments

@deyanmihaylov
Copy link

I am using the C interface of gmpy2 in cython and it has been working great. However, I have not found out how to access the absolute value function abs() in this context.

All of the following fail with import (or no module found) errors:
from gmpy2 import abs as gmpabs
from gmpy2_context import abs as gmpabs
from gmpy2_abs import abs as gmpabs

Is there a way to access the abs() function from cython, or do I need to make my own alternative?

@deyanmihaylov deyanmihaylov changed the title Access to abd from C interface Access to abs() from C interface Sep 18, 2024
@skirpichev
Copy link
Contributor

What's wrong with using abs?

from gmpy2 cimport *

cdef extern from "gmp.h":
    void mpz_set_si(mpz_t, long)

import_gmpy2()   # needed to initialize the C-API

cdef mpz z = GMPy_MPZ_New(NULL)
mpz_set_si(MPZ(z), -7)

print(abs(z))

If you are working with C API directly, you can just use mpz_abs on z field of MPZ_Object struct.

@skirpichev
Copy link
Contributor

@deyanmihaylov, is this still an issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants