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

Add MPFR support to ForeignFunctions package #3124

Merged
merged 11 commits into from
Feb 12, 2024

Conversation

d-torrance
Copy link
Member

For example:

i1 : needsPackage "ForeignFunctions";

i2 : mpfrAdd = foreignFunction("mpfr_add", void, {mpfrT, mpfrT, mpfrT, int})

o2 = mpfr_add

o2 : ForeignFunction

i3 : x = mpfrT 0p100

o3 = 0

o3 : ForeignObject of type mpfr_t

i4 : mpfrAdd(x, numeric(100, pi), exp 1p100, 0)

i5 : x

o5 = 5.85987448204883847382293085463

o5 : ForeignObject of type mpfr_t

i6 : value oo

o6 = 5.85987448204883847382293085463

o6 : RR (of precision 100)

Matches the behavior of mpfrT.  Main changes:

* ffi.d code now expects a sequence of 3 elements, with 0 as the
  "bits", which simplifies the construction at top level
* use moveToZZ so that all the allocated memory will be garbage
  collected
* comments!
@mahrud
Copy link
Member

mahrud commented Feb 9, 2024

I'm a bit confused. Ideally one shouldn't need any changes to the interpreter/engine to connect to a new library using foreign functions, right? Is this just an optimization then?

@d-torrance
Copy link
Member Author

I'm a bit confused. Ideally one shouldn't need any changes to the interpreter/engine to connect to a new library using foreign functions, right? Is this just an optimization then?

Correct. This is so we can call functions from other libraries that might use MPFR. The specific case I have in mind is the ball arithmetic stuff in FLINT. It would be possible to call everything just using double's, but it would be nice to allow for arbitrary precision.

@DanGrayson DanGrayson merged commit 962280c into Macaulay2:development Feb 12, 2024
5 of 6 checks passed
@d-torrance d-torrance deleted the mpfr-ffi branch March 11, 2024 12:27
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

Successfully merging this pull request may close these issues.

3 participants