https://swift.org/blog/numerics/

Steve Canon is a member of Apple’s Swift Standard Library team. Previously he spent a decade working on Apple’s math library and the Accelerate framework.

I’m excited to announce a new open-source project for the Swift ecosystem, Swift Numerics! Swift Numerics will provide the building blocks of numerical computing in Swift, as a set of fine-grained modules bundled together into a single Swift package. My hope is that we can quickly fill some important gaps in the Standard Library’s existing APIs, and unlock new domains of programming to the Swift language.

I’ve seeded the repository with two much-requested modules that are immediately useful for computational mathematics: Real (providing the functionality of SE-0246) and Complex (providing complex numbers and arithmetic). Let’s take a look at what they do:

Real Numbers

SE-0246 proposed an API for “basic math functions” that would make operations like sine and logarithm available in generic contexts. It was accepted, but because of limitations in the compiler, the API cannot yet be added to the Standard Library in a source-stable manner. The Real module provides that API as a separate module so that you can use it right away to get access to the improved API for these operations in your projects.

The module defines three protocols. The most general is ElementaryFunctions, which makes the following functions available:

The RealFunctions protocol refines ElementaryFunctions, and adds operations that are difficult to define or implement over fields more general than the real numbers: