A Compositional Numeric Library for C++
Clone or download
johnmcfarlane Merge pull request #339 from johnmcfarlane/338
MSVC C++17 support

- since MSVC CI was last looked at C++17 support has matured
- but the __cplusplus__ macro doesn't reflect /std switch by default
- Appveyor CI now tests 11, 14 and 17
- variable template features are now gated on feature test macros
- numerous fixes were applied so that MSVC now largely supports C++17
Latest commit 3ce341a Dec 8, 2018


CNL: A Compositional Numeric Library for C++

Build Status Build status CircleCI

CNL is a numerics library written in C++ which aims to do for int what the STL does for arrays. Its main roles are to help:

  • approximate real numbers using fixed-point arithmetic;
  • detect and prevent overflow and
  • increase precision through alternative rounding modes.

A compositional design promotes seamless interoperability between numeric types. And by providing the thinnest wrappers over the widest range of numeric types, CNL aims to assist the development of:

  • large-scale simulations including video games and scientific models;
  • resource-constrained applications on embedded and mobile devices and
  • math-intensive operations on specialized hardware such as GPUs and FPGAs.

The library's APIs are developed in colaboration with standardization bodies such as The C++ Standards Committee and members of The Khronos Group Inc. and it serves as a reference implementation for sections of the C++ Numbers Technical Specification. Please read proposals, P0037 and P0554 for more details.



Tested on Travis and CircleCI.



  • Boost - facilitates multiprecision support
  • Doxygen - generates documentation in the doc/gh-pages directory


Tested on AppVeyor and on Windows 10 Professional with CMake 3.8.0. Requires:

  • MSBuild 15.0 (VS 2017)
  • CMake 3.8.0



The library is hosted on GitHub:

cd /some/directory
git clone https://github.com/johnmcfarlane/cnl.git


CNL is a header-only library so there is no need to build it. However, it comes with a number of tests and benchmarks.

Running Tests

  1. Generate the build system:

    cmake /some/directory/cnl

  2. Build tests:

    • For Linux (in parallel using N cores):

      cmake --build . --target Tests -- -j N

    • For Windows:

      cmake --build . --target src/test/Tests

  3. Run tests:


Running Benchmarks

  1. Generate the build system (optimized):

    cmake -DCMAKE_BUILD_TYPE=Release /some/directory/cnl

  2. Build benchmarks:

    cmake --build . --target Benchmark

  3. Run benchmarks:


Additional build system generation options:

  1. To describe CNL build options:

    cmake -LH /some/directory/cnl

  2. Then to apply an option, e.g. to disabled exceptions:

    cmake -DEXCEPTIONS=OFF /some/directory/cnl


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/fixed_point.h>

// or to include all CNL types:
#include <cnl/all.h>

See example program, Tau, for more details.

Further Reading

Contact Information

All feedback greatly appreciated.

Developed with CLion: A Cross-Platform IDE for C and C++ by JetBrains.