This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
cppduals is a header-only C++17 template library for dual number arithmetic and forward-mode automatic differentiation. Dual numbers have the form `a + b·ε` where `ε² = 0`, enabling exact derivative computation. Supports recursive nesting (`dual<dual<T>>`) for higher-order derivatives and composition with `std::complex`.
## Build Commands
The project uses CMake (3.14+) with a Makefile wrapper for convenience.
```bash
# Debug build with Clang (includes coverage support)
make clang
# Release build with Clang
make clangr
# Run tests (builds clangr first)
make test
# Coverage report
make cov # Clang — report at Build-clang/coverage/html/index.html
make cov-gcc # GCC — report at Build-cc/coverage/html/index.html
./Build-clangr/tests/test_dual # or any test binary in tests/
ctest --test-dir Build-clangr -R test_dual # by name pattern
# Clean everything
make distclean
```
Build output goes to `Build-clang/`, `Build-clangr/`, `Build-cc/`, `Build-ccr/`, `Build-osx/` depending on target.
## Architecture
**Core library** (`duals/`): Header-only, no compilation needed for library users.
-`duals/dual` — Main `duals::dual<T>` class template with all math functions (sin, cos, exp, log, pow, etc.) and operator overloads. This is the primary public API (~1900 lines).
-`duals/dual_eigen` — Eigen matrix library integration: NumTraits, type promotion, and vectorized packet operations for dual types.
**Dependencies** are fetched via CMake FetchContent in `thirdparty/CMakeLists.txt`: Google Test, Eigen, fmt, Google Benchmark.
## Versioning and Releases
The version is defined in the top-level `CMakeLists.txt` (`project(cppduals VERSION X.Y.Z ...)`). GitLab CI (`.gitlab-ci.yml`) handles packaging and release creation automatically when a tag is pushed:
-**upload** stage: creates a header-only tarball and publishes it to the GitLab package registry
-**release** stage: creates a GitLab release linked to the package
To cut a new release:
```bash
# 1. Update the VERSION in CMakeLists.txt
# project(cppduals VERSION 0.6.4 ...)
# 2. Commit the version bump
git commit -am"Bump version to 0.6.4"
# 3. Tag and push — CI does the rest
git tag v0.6.4
git push origin master --tags
```
The tag name must match the format `vX.Y.Z` (e.g. `v0.6.4`). CI uses `$CI_COMMIT_TAG` to derive the package version.
## Code Conventions
- Comment WHY, not WHAT.
- License: MPL 2.0.
- Must compile on GCC, Clang, and MSVC.
- Performance goal: match or exceed `std::complex<>` speed for equivalent operations.