Skip to content

Universal Numbers Library

Alternatives to native integer and floating-point for mixed-precision algorithm development and optimization. Tailored arithmetic for Deep Learning, DSP, HPC, and embedded applications.

30+ Number Systems

Integers, fixed-point, classic floats, posits, logarithmic, interval, multi-precision, AI quantization formats, and more.

Header-Only

No external dependencies. Just #include and go. Pure C++20 templates.

Plug-in Replacement

Template your algorithms once, switch arithmetic types freely with zero code changes.

Comprehensive Testing

Exhaustive regression suites for every type. CI on GCC, Clang, and MSVC.

#include <iostream>
#include <universal/number/cfloat/cfloat.hpp>
template<typename Real>
Real MyKernel(const Real& a, const Real& b) {
return a * b;
}
int main() {
using namespace sw::universal;
// half-precision IEEE-754
half ha = sqrt(2);
half hb = 3.14159265358979;
half hc = MyKernel(ha, hb);
std::cout << "Result: " << hc << '\n';
std::cout << "Bits : " << to_binary(hc) << " : " << color_print(hc) << '\n';
// single-precision IEEE-754
single fa = sqrt(2);
single fb = 3.14159265358979;
single fc = MyKernel(fa, fb);
std::cout << "Result: " << fc << std::endl;
std::cout << "Bits : " << to_binary(fc) << " : " << color_print(fc) << std::endl;
}

To compile (assuming Universal is cloned to ./universal):

Terminal window
g++ -std=c++20 -I universal/include/sw -o kernel kernel.cpp

The library requires C++20 and is header-only with no external dependencies. The include path points to include/sw/ because headers use #include <universal/...> paths.

| Category | Types | |----------|-------| | Integer & Fixed-Point | integer, fixpnt, dfixpnt, rational | | Configurable Float | cfloat, bfloat16, areal, dfloat, hfloat | | AI Quantization | microfloat, e8m0, mxfloat, nvblock | | Unum Family | unum1, unum2, posit, takum | | Logarithmic | lns, dbns | | Interval | valid, interval, sorn | | Extended Precision | dd, qd, dd_cascade, td_cascade, qd_cascade | | Kulisch Super-Accumulator | quire for half, float, double, cfloat, posit, fixpnt, lns, dbns, integer |

| Category | Types | |----------|-------| | Adaptive Integer | einteger | | Adaptive Decimal | edecimal | | Adaptive Rational | erational | | Adaptive Float | efloat | | Adaptive Real | ereal |

Please cite our JOSS paper if you use Universal in your work.