CNL
rev.0.1.0
Compositional Numeric Library

The Compositional Numeric Library (CNL) is a C++ library of fixedprecision numeric classes which enhance integers to deliver safer, simpler, cheaper arithmetic types.
CNL improves on numbers the same way that the STL improves on arrays and smart pointers improve on pointers.
Uses include
The CNL project is published under the Boost licence and can be found online at github.com/johnmcfarlane/cnl.
The core numeric types of CNL are:
Each of these types solves a single problem when used alone.
In combination, the core types produce composites which address multiple concerns.
Provided composite types include:
Many more combinations are possible. For example:
safe_integer
(overflow_integer and elastic_integer);wide_elastic_integer
(elastic_integer and wide_integer) andsafe_fraction
(fraction and safe_integer
).The following examples can be found in the test suite.
The fixed_point type adds a scaling exponent to integers. This enables the integer to represent very big or very small values.
Specializations of fixed_point behave a lot like native C/C++ numeric types. Operators are designed to behave in an way which is both predictable and efficient.
But one size does not fit all. Different applications of the same operation might call for different tradeoffs between storage, precision, safety and speed. Named functions provide finetuned control over arithmetic results.
Because one size does not fit all, fixed_point is designed to make it easy to tailor new arithmetic types. The elastic_number type illustrates this. As each calculation requires more digits, so the results of elastic_number operations allocate more storage.