| Branch | Linux | macOS | Windows |
|---|---|---|---|
main |
|||
release/0.3.x |
CCMath is a header-only library with a <cmath>-style API. The same entry points constexpr-evaluate where the standard and compiler allow, dispatch to portable runtime implementations elsewhere, and can use SIMD on selected functions when the target supports it.
This README describes what CCMath is working toward. Some claims here reflect goals still in progress. See STATUS.md for current implementation status by module and function.
For approximation-driven function work, see the implementation guide in APPROXIMATING_FUNCTIONS.pdf.
Most <cmath> implementations prioritize different tradeoffs. Few combine standards-oriented semantics, constexpr evaluation, full runtime paths, SIMD, and portable in-tree code.
| Library | Standards-Oriented | Constexpr | Runtime | SIMD | Portable Implementation |
|---|---|---|---|---|---|
std::cmath |
Yes | Partial | Yes | Vendor dependent | No |
| Compiler builtins | Partial | Partial | Yes | No | No |
| GCEM | Partial | Yes | Limited | No | Yes |
| OpenLibm | Yes | No | Yes | Limited | Yes |
| SLEEF | Partial | No | Yes | Yes | Yes |
| CCMath | Yes | Yes | Yes | Yes | Yes |
CCMath targets:
- Standards conformance
- Compile-time evaluation
- Runtime execution
- SIMD acceleration
- Numerical correctness
- Cross-platform portability
These goals overlap with the comparison columns plus numerical validation. Per-function progress is tracked in STATUS.md.
CCMath is designed to closely follow the behavior specified by the C and C++ standards for mathematical functions.
This includes:
- Function semantics
- Domain handling
- Range handling
- NaN propagation
- Infinity behavior
- Floating-point classification
- Rounding behavior
- Edge-case handling
Implemented functions follow the rules the C and C++ standards set for <cmath>.
constexpr auto value = ccm::sin(0.5);
static_assert(value > 0.0);There is no separate constexpr API. When constant evaluation is possible, the public symbol participates in it.
double result = ccm::exp(x);When constant evaluation is not possible, the same symbols dispatch to runtime paths.
Selected functions pick up SIMD on supported targets:
- SSE2
- SSE4
- AVX2
- ARM NEON
We aim for correct rounding under all four IEEE rounding modes. Coverage is function-by-function: some paths are validated today under all modes, while other functions still target round-to-nearest ties-to-even first.
ULP harnesses, all-mode rounding probes, worst-case grids, and cross-compiler CI matrices live in-tree. The validation section below describes how they run in practice.
Work spans trigonometric, exponential, power, rounding, classification, and utility categories from the C and C++ mathematical library. Several modules are still in flight. STATUS.md lists what ships today and what remains open.
Validation follows patterns from LLVM-libc, CORE-MATH, and glibc. CI covers:
- Linux
- macOS
- Windows
- GCC
- Clang
- Apple Clang
- MSVC
- C++17
- C++20
- C++23
- C++26 / latest
- Debug
- Release
The simple suite runs on every CI job:
ctest -L simpleThis suite exercises public ccm::* entry points and includes:
- Smoke testing
- Standards edge cases
- ULP checks against the active platform libm
- Regression testing
The rigorous suite runs in dedicated CI jobs:
ctest -L rigorousRigorous jobs compare against MPFR and CORE-MATH oracles.
Within a rigorous build, MPFR-backed tests use the mpfr label:
ctest -L mpfrIncludes:
- Extended function corpora
- Exceptional-value matrices
- Adversarial search
Linux and macOS use system MPFR/GMP.
Windows uses MPFR provided through vcpkg.
Within a rigorous build, CORE-MATH-backed tests use the coremath label:
ctest -L coremathCorrectly-rounded reference comparisons under all four IEEE rounding modes on finite inputs.
When available, CCMath uses:
- Gappa
- Sollya
to refresh and verify proof artifacts for supported implementations.
Fuzz smoke tests run in dedicated macOS and Linux CI jobs with full LLVM Clang (libFuzzer requires the fuzzer sanitizer runtime). Windows matrix jobs use MSVC and are outside libFuzzer coverage today.
CodeQL, OpenSSF Scorecard, warning-as-error builds, and strict compiler warning gates run in CI.
clang-format runs in CI on every platform matrix job and on pull requests that touch headers. clang-tidy is available locally via lint.sh and lint.bat.
#include <ccmath/ccmath.hpp>
#include <iostream>
int main() {
constexpr double result = ccm::sqrt(25.0);
std::cout << result << '\n';
}#include <ccmath/math/expo/log.hpp>
#include <iostream>
int main() {
constexpr double result = ccm::log(12.0);
std::cout << result << '\n';
}include(FetchContent)
FetchContent_Declare(
ccmath
GIT_REPOSITORY https://github.com/Rinzii/ccmath.git
GIT_TAG v0.3.0
)
FetchContent_MakeAvailable(ccmath)
target_link_libraries(
main
PRIVATE
ccmath::ccmath
)You may also vendor the headers directly.
CMake is the primary and authoritative build system. Meson and Premake support library consumption only: include paths, compile definitions, the generated version.hpp, and the library-required feature validation that a consumer needs. They do not define examples, smoke binaries, tests, benchmarks, fuzzing targets, or third-party dependency fetches.
After configuring CMake, regenerate the secondary build files:
cmake --preset ninja-clang-debug -DCCMATH_BUILD_TESTS=OFF -DCCMATH_BUILD_EXAMPLES=OFF
cmake --build out/build/ninja/ninja-clang-debug --target ccmath-generate-secondary-buildsMeson consumer usage after regeneration:
ccmath_dep = dependency('ccmath', fallback : ['ccmath', 'ccmath_dep'])
executable('my-app', 'main.cpp', dependencies : ccmath_dep)Premake consumer usage after regeneration:
include("../ccmath/premake5.lua")
project "my-app"
kind "ConsoleApp"
language "C++"
files { "main.cpp" }
ccmath.use()The generated root meson.build exposes ccmath_dep and overrides the ccmath dependency name for Meson consumers. The generated root premake5.lua exposes ccmath.use(), ccmath.include_dirs(), and ccmath.defines() for Premake consumers. Library-facing options are declared once in cmake/config/BuildManifest.cmake and exported through ccmath-build-manifest.json.
integration/vendored-consumer simulates an external project that vendors CCMath headers under third_party/ccmath. CI copies the public headers and generated version.hpp, then builds the consumer with CMake, Meson, and Premake.
cmake --preset ninja-clang-debug -DCCMATH_BUILD_TESTS=OFF -DCCMATH_BUILD_EXAMPLES=OFF
bash tools/integration/prepare_vendored_tree.sh out/build/ninja/ninja-clang-debug
cmake -S integration/vendored-consumer -B integration/vendored-consumer/build-cmake -G Ninja
cmake --build integration/vendored-consumer/build-cmake
meson setup integration/vendored-consumer/build-meson integration/vendored-consumer
meson compile -C integration/vendored-consumer/build-meson
cd integration/vendored-consumer && premake5 gmake && make config=debugTypical local configuration:
cmake -B build-rigorous -G Ninja \
-DCCMATH_BUILD_RIGOROUS_TESTS=ON \
-DCCMATH_ENABLE_MPFR_TESTS=ON \
-DCCMATH_ENABLE_COREMATH_TESTS=ON \
-DCCMATH_COREMATH_ROOT=/path/to/coremath-prefixBuild a CORE-MATH prefix using:
tools/coremath/build_prefix.shOn Windows, pass:
-DVCPKG_MANIFEST_DIR=cmake/vcpkgalong with a vcpkg toolchain file to obtain MPFR.
See the workflow definitions in .github/workflows for the exact CI configurations.
The library itself has no required dependencies.
Optional packages used for testing, benchmarking, and fuzzing are documented in thirdparty/README.md.
- GCC 11.1+
- Clang 9.0.0+
- Apple Clang 14.0.3+
- MSVC 19.26+
- Intel DPC++ 2022.0.0+
- NVIDIA HPC SDK 22.7+
Note
Minimum compiler versions are still being refined and should be considered guidance rather than a finalized support matrix.
The following projects publicly use CCMath:
If your project uses CCMath and is publicly available, open a PR to add it to this list.
See CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md. Bug reports and design questions go to GitHub Issues or Discord.
Apache License v2.0 with LLVM Exceptions. See LICENSE.
Algorithm and validation ideas draw on LLVM-libc, GCC libm, CORE-MATH, glibc math, and OpenLibm.
