apple/swift-numerics
63.9
Adequate · 15 November 2026
4.8k
lines of production code
Swift
with C
5
measurements over time
What this system is
This system is the Swift Numerics library, providing a comprehensive suite of generic mathematical types and operations for Swift developers. It offers robust support for complex number arithmetic, generic floating-point abstractions via the Real protocol, and extended integer utilities including saturation and precise rounding. The library is structured into modular components to facilitate clean imports and maintainable, high-precision numerical computations across various platforms.
How it got here
2019 — Package restructuring and test expansion
8 changes.
The project reorganized its package structure to align with modern Swift Package Manager conventions, introducing new modular components like ComplexModule and an umbrella Numerics module. This refactoring involved removing legacy shim layers and consolidating arithmetic logic, while significantly expanding test coverage for complex numbers, real arithmetic, and elementary functions to ensure robust numerical behavior.
2020–2021 — Modularization and generic math expansion
7 changes.
The project restructured its codebase into granular modules, introducing CMake build support and internal shims for C math bindings. It expanded its numerical capabilities by adding the RealModule for generic floating-point abstractions and the IntegerUtilities module for precise integer operations like rounding and saturation.
Features
Add NumericsShims header with C math function bindings
The \_NumericsShims module now includes a new header file that provides inline C bindings for standard math functions (such as trigonometric, exponential, and logarithmic operations) for both float and double types. This allows Swift code to access these low-level mathematical operations via the \_NumericsShims module, facilitating more efficient numerical computations by leveraging compiler built-ins and platform-specific implementations where necessary.
_Sources/\NumericsShims/include · high confidence
Introduce RealModule for generic floating-point math
This change introduces the RealModule, a new library component that provides the \Real\ protocol and related abstractions for writing generic numerical code. The module defines \ElementaryFunctions\ and \RealFunctions\ protocols to expose standard math operations (such as trigonometric, exponential, and logarithmic functions) in a generic context, along with \AlgebraicField\ for field-like arithmetic. It includes concrete conformances for \Float\, \Double\, \Float16\, and \Float80\, implementing these operations via the C standard math library (\libm\) or platform-specific workarounds. Additionally, the module provides \Augmented\ arithmetic utilities for high-precision summation and product operations, as well as \ApproximateEquality\ extensions for floating-point comparisons.
Sources/RealModule · high confidence
New IntegerUtilities module with rounding, saturation, and GCD operations
The new IntegerUtilities module introduces several integer operations that were previously unavailable or limited in Swift. It adds division with explicit rounding rules (e.g., .up, .down, .toNearestOrEven) via \divided(by:rounding:)\ on \BinaryInteger\ and \SignedInteger\, allowing precise control over quotient and remainder behavior. It also provides bitwise shifts with rounding (\shifted(rightBy:rounding:)\) and saturating arithmetic methods (\addingWithSaturation\, \multipliedWithSaturation\, etc.) on \FixedWidthInteger\ to clamp results instead of trapping or wrapping. Additionally, it includes a \gcd\ free function using the Euclidean algorithm and bitwise rotation methods (\rotated(left:)\, \rotated(right:)\).
Sources/IntegerUtilities · high confidence
New \_TestSupport module for internal testing utilities
A new internal \\_TestSupport\ module has been added to provide shared testing infrastructure for the Numerics library. This module introduces the \DoubleWidth\ type, allowing users to represent integers with twice the bit width of a base type (e.g., \DoubleWidth\<Int\>\) to preserve full precision from wide arithmetic operations. It also includes helper utilities such as a \blackHole\ function to prevent compiler optimizations from removing test code, error calculation functions for comparing floating-point and complex results, an iterable \Interval\ type for generating test ranges, and a \FixedWidthFloatingPoint\ protocol to standardize floating-point types with fixed-width exponents and significands.
_Sources/\TestSupport · high confidence
New umbrella module for unified import
A new umbrella module named Numerics has been added, which re-exports the ComplexModule, IntegerUtilities, and RealModule. This allows users to access the complete Swift Numerics public API with a single import statement instead of importing each sub-module individually.
Sources/Numerics · high confidence
Removals
Removal of NumericsShims module
The NumericsShims module, which previously provided inline C wrappers for standard math functions (such as trigonometric, exponential, and logarithmic operations) for both float and double types, has been removed. This change indicates that the project no longer requires this specific shim layer, likely due to the availability of native Swift built-ins or other underlying library improvements, simplifying the codebase by eliminating these redundant C-level implementations.
Sources/ElementaryFunctions, Sources/NumericsShims · high confidence
Architecture
Refactored Complex module into granular source files with CMake build support
The Complex module has been restructured from a single monolithic file into multiple, finer-grained source files (e.g., Complex+AdditiveArithmetic.swift, Complex+ElementaryFunctions.swift) to improve organization and maintainability. This change also introduces a CMake-based build system (CMakeLists.txt) for the module, allowing it to be built as part of a larger CMake project. The refactoring preserves all existing functionality, including conformances to protocols like AdditiveArithmetic, AlgebraicField, Hashable, and Codable, as well as the implementation of elementary functions and arithmetic operations.
Sources/ComplexModule · high confidence
Behavioural changes
Complex type refactored with new arithmetic and property behaviors
The Complex type has undergone significant structural changes: the Arithmetic.swift file is removed, implying a reorganization of arithmetic operations; the Complex struct now uses @\_fixed\_layout instead of @\_fixed\_layout (note: diff shows deletion of @\_fixed\_layout, likely replaced or removed); the real and imaginary properties now return .nan for non-finite values instead of the raw components; division by zero now returns .infinity instead of potentially throwing or returning undefined; and the type no longer conforms to Numeric but likely to SignedNumeric (based on commit message, though diff doesn't show conformance changes directly, the removal of Arithmetic.swift suggests protocol conformances were moved or changed). These changes affect how Complex numbers behave in arithmetic operations, property access, and error handling.
Sources/Complex · medium confidence
Internal NumericsShims module renamed and migrated to CMake
The internal implementation module previously named NumericsShims has been renamed to \_NumericsShims (including its source file, header, and build target) to reflect its status as an internal detail without a stable public API. The build system for this module has been updated to use CMake, replacing the previous build configuration, and the module now explicitly links against the math library on Linux.
_Sources/\NumericsShims · high confidence
Test coverage
Added test suite for IntegerUtilities module; Expanded test coverage for Complex number arithmetic and elementary functions; Expanded test coverage for Real module arithmetic and functions; Removal of LinuxMain.swift test entry point; Removal of legacy elementary function test suite.
Dependencies
Swift Numerics package structure and module reorganization
The Swift Numerics package has been restructured to align with modern Swift Package Manager conventions. The minimum supported Swift version is now 5.9 (with legacy support for 5.4 via tools version settings). The public API is exposed through new modules: ComplexModule, RealModule, and Numerics, replacing the previous Complex and ElementaryFunctions libraries. A new IntegerUtilities module has been added. The internal \_NumericsShims module is now a system library target, and RealModule explicitly links the math library (libm) on Linux and Android. Test targets have been reorganized, with a new \_TestSupport module shared by ComplexTests, IntegerUtilitiesTests, and RealTests.
(dependencies) · high confidence
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 65 → 64 (-1.5)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.4) — scores are not directly comparable.
Lenses
- Code Health 91 → 84 (-7.2)
- Architecture 94 → 93 (-1.0)
- Maturity 57 → 59 (+1.7)
- Readiness 55 → 53 (-1.8)
- Security 100 → 100 (+0.0)
New (10)
- Edited copies of one member (3 members, 10+ corresponding lines) (Sources/RealModule/Double+Real.swift)
- Edited copy of a member (10 corresponding lines) (Sources/RealModule/AugmentedArithmetic.swift)
- Edited copy of a member (11 corresponding lines) (Sources/_TestSupport/DoubleWidth.swift)
- Edited copy of a member (14 corresponding lines) (Sources/ComplexModule/Complex+ElementaryFunctions.swift)
- Edited copy of a member (16 corresponding lines) (Sources/_TestSupport/DoubleWidth.swift)
- Edited copy of a member (17 corresponding lines) (Sources/ComplexModule/Complex+ElementaryFunctions.swift)
- Edited copy of a member (18 corresponding lines) (Sources/_TestSupport/DoubleWidth.swift)
- Edited copy of a member (19 corresponding lines) (Sources/_TestSupport/DoubleWidth.swift)
- Edited copy of a member (27 corresponding lines) (Sources/RealModule/Double+Real.swift)
- Edited copy of a member (7 corresponding lines) (Sources/_TestSupport/DoubleWidth.swift)
Written by cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
apple/swift-numerics was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 15 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 669f6185187f8e1b5857a25c4bbe6c34a3a02b96 — the exact code this score is about.
- Scored under rubric-2026.11.4 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.65+preprod-3c33c1882dc1.