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.

CategoryTypes
Integer & Fixed-Pointinteger, fixpnt, dfixpnt, rational
Configurable Floatcfloat, bfloat16, areal, dfloat, hfloat
AI Quantizationmicrofloat, e8m0, mxfloat, nvblock
Unum Familyunum1, unum2, posit, takum
Logarithmiclns, dbns
Intervalvalid, interval, sorn
Extended Precisiondd, qd, dd_cascade, td_cascade, qd_cascade
Kulisch Super-Accumulatorquire for half, float, double, cfloat, posit, fixpnt, lns, dbns, integer
CategoryTypes
Adaptive Integereinteger
Adaptive Decimaledecimal
Adaptive Rationalerational
Adaptive Floatefloat
Adaptive Realereal

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