A Compositional Numeric Library for C++
The Compositional Numeric Library (CNL) is a C++ library of fixed-precision numeric classes which enhance integers to deliver safer, simpler, cheaper arithmetic types. Documentation can be found here. You can try out CNL on Compiler Explorer here.
CNL is particularly well-suited to:
The latest version of CNL requires a C++20-compatible tool chain. (Version 1.x supports C++11.) CNL is continually tested on the following systems:
Tested:
Tested:
Tested:
CMake scripts are provided.
mkdir build && cd build
cmake ..
cmake --build . --target install
Note: you may need user privileges to install the library.
Alternatively, you can install to user directory using CMAKE_INSTALL_PREFIX
:
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:FILE=/home/username/someplace ..
cmake --build . --target install
Alternatively, CNL is a header-only library so you can simply point to the include directory
c++ -isystem /path/to/cnl/include -std=c++20 my_program.cpp
or even include the root header directly in your code:
#include "/path/to/cnl/include/cnl/all.h"
The test suite uses CMake and depends on Google Test and Google Benchmark. Optional integration tests use Boost.Multiprecision.
Conan can be used to pull in essential dependencies. This example assumes GCC but other tool chain files are provided:
cd build
conan profile new --detect --force default
conan profile update settings.compiler.libcxx=libstdc++11 default # GCC/Clang only
conan profile update env.CONAN_CMAKE_TOOLCHAIN_FILE=../test/toolchain/gcc.cmake default # GCC only
conan install --build=missing --options test=unit ..
... and then configure, build and run unit tests:
conan build --configure --build --test ..
To run benchmarks, use --options test=benchmark
...
conan install --build=missing --options test=benchmark ..
then configure and build
conan build --configure --build ..
and finally run explicitly to see the results.
./test/benchmark/test-benchmark
The API is exposed through headers in the include directory. Add this to your system header list and include, e.g.:
// to use a specific type:
#include <cnl/scaled_integer.h>
// or to include all CNL types:
#include <cnl/all.h>
Examples of projects using CNL:
All feedback greatly appreciated.