Skip to content
CAI
Software that uses CAICheck a score

apple/swift-numerics

63.8

Adequate · 1 October 2026

4.7k

lines of production code

Swift

with C

2

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

This system is the Swift Numerics library, providing a comprehensive suite of mathematical utilities for Swift developers. It offers generic floating-point abstractions via the Real module, precise complex number arithmetic, and extended integer operations including saturation and rounding. The package is structured into distinct modules for complex numbers, real numbers, and integer utilities, all accessible through a unified umbrella module.

How it got here

2019 — Package restructuring and test expansion

8 changes.

The Swift Numerics package was reorganized to align with modern Swift Package Manager conventions, introducing a unified umbrella module and splitting functionality into specialized sub-modules. This structural overhaul was accompanied by the removal of legacy shim layers and manual test entry points, while significantly expanding automated test coverage for complex arithmetic, real number operations, and elementary functions.

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 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 eliminates the need for a separate shim layer, as the underlying functionality is now handled directly via compiler built-ins or other mechanisms, simplifying the build structure for users relying on these numeric utilities.

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 watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

Score

  • CAI 59 → 64 (+4.5)
  • Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.

Lenses

  • Code Health 88 → 88 (+0.0)
  • Architecture 70 → 94 (+23.7)
  • Maturity 53 → 53 (+0.6)
  • Readiness 49 → 55 (+5.4)
  • Security 100 → 100 (+0.0)

Resolved (3)

  • Documentation: no installation or build instructions (README.md)
  • Documentation: no usage examples (README.md)
  • Hotspot: Sources/IntegerUtilities/RoundingRule.swift (Sources/IntegerUtilities/RoundingRule.swift)

New (3)

  • Coverage not measured — Swift suite
  • Documentation: no architecture or design documentation
  • Off the main sequence: IntegerUtilities (SwiftPM)

Written by watchdog.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 1 October 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit a7d826ead09420d5e38221ff76c3e0ec9ea4ea8b — the exact code this score is about.
  • Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer preprod-e569280dd5e2.