Files
swift-numerics/Sources/RealModule/Documentation.docc/RealModule.md
T
Stephen Canon 41d7ab5c35 Merge pull request #355 from reginaldalfret/docs/approximate-equality
docs: add dedicated documentation for ApproximateEquality
2026-10-08 10:59:00 -04:00

1.5 KiB

RealModule

Extensions on the Swift standard library that provide functionality for floating-point types.

Overview

RealModule provides four protocols that extend the standard library's numeric protocol hierarchy: AlgebraicField, ElementaryFunctions, RealFunctions, and Real.

Types conforming to AlgebraicField represent fields. These are the mathematical structures that typically form the elements of vectors and matrices, so this protocol is appropriate for writing generic code to do linear-algebra-type operations.

ElementaryFunctions provides bindings for the "math functions": the logarithm and exponential functions, sine, cosine and tangent as well as their inverses, and other functions that you may be familiar with from trigonometry and calculus. RealFunctions refines ElementaryFunctions and provides functions that are primarily used with the real numbers, such as atan2, erf and gamma, and the base-2 and -10 logarithm and exponential funtions.

The Real protocol is a convenient name for the intersection of FloatingPoint, RealFunctions, and AlgebraicField; this is the protocol that you are most likely to want to constrain to when writing generic "math" code that works with floating-point types.

RealModule also provides isApproximatelyEqual methods for comparing floating-point values up to a tolerance, which is almost always what you want instead of an exact == comparison. See doc:ApproximateEquality for details.