Macaulay2 » Documentation
Packages » ForeignFunctions :: ForeignFunctions
next | previous | forward | backward | up | index | toc

ForeignFunctions -- foreign function interface

Description

This package provides the ability to load and call "foreign" functions from shared libraries and to convert back and forth between Macaulay2 things and the foreign objects used by these functions. It is powered by libffi.

As a simple example, we call the cos function from the C standard library, which sends a double (a real number represented as a double-precision floating point number) to another double, the cosine of the input.

i1 : mycos = foreignFunction("cos", double, double)

o1 = cos

o1 : ForeignFunction
i2 : mycos pi

o2 = -1

o2 : ForeignObject of type double
i3 : value oo

o3 = -1

o3 : RR (of precision 53)

In this example, we created a ForeignFunction object using the foreignFunction constructor method and specified that both its output and input were instances of the double type, which is one of several ForeignType objects that are available.

See also the following additional examples:

Menu

Examples

Types

Author

Certification a gold star

Version 0.4 of this package was accepted for publication in volume 15 of Journal of Software for Algebra and Geometry on 2024-12-17, in the article ForeignFunctions package for Macaulay2 (DOI: 10.2140/jsag.2025.15.1). That version can be obtained from the journal.

Version

This documentation describes version 0.5 of ForeignFunctions.

Citation

If you have used this package in your research, please cite it as follows:

@misc{ForeignFunctionsSource,
  title = {{ForeignFunctions: foreign function interface. Version~0.5}},
  author = {Doug Torrance},
  howpublished = {A \emph{Macaulay2} package available at
    \url{https://github.com/Macaulay2/M2/tree/master/M2/Macaulay2/packages}}
}

@article{ForeignFunctionsArticle,
  title = {{ForeignFunctions package for \emph{Macaulay2}}},
  author = {Doug Torrance},
  journal = {Journal of Software for Algebra and Geometry},
  volume = {15},
  year = {2024},
}

Exports

For the programmer

The object ForeignFunctions is a package, defined in ForeignFunctions.m2.


The source of this document is in ForeignFunctions.m2:752:0.