Skip to content

vargalabs/libdecimal

Repository files navigation

CI codecov MIT License DOI GitHub release Documentation

Build Matrix

OS / Compiler GCC 13 GCC 14 GCC 15 Clang 17 Clang 18 Clang 19 Clang 20
Ubuntu 22.04 gcc13 gcc14 gcc15 clang17 clang18 clang19 clang20
Ubuntu 24.04 gcc13 gcc14 gcc15 clang17 clang18 clang19 clang20

libdecimal — Deterministic Decimal Arithmetic Built on Intel LIBBID

libdecimal is a header-only, production-grade decimal arithmetic library built for systems where correctness is not negotiable. If your P&L depends on the last digit — you’re in the right place. If your connectivity stack (e.g. Interactive Brokers) already relies on Intel LIBBID — this fits naturally. This is not a “numeric playground” — it’s infrastructure. For

  • trading engines
  • risk systems
  • settlement pipelines
  • cryptographic finance primitives

Why This Exists

  • Intel LIBBID is already in your stack — but the API is painful
  • The build system failed for you, we had it covered
  • Clean, modern C++ layer over LIBBID (no wrapper spaghetti)
  • Exact BID binary representation for interop & persistence
  • You are looking for an alternative to Boost.Decimal

You get:

  • Exact base-10 semantics
  • Deterministic cross-platform results
  • Zero rounding surprises
  • Precision suitable for financial systems
  • Compile-time friendly (constexpr where it matters)
  • Clean integration with modern C++ (C++20/23)

Who This Is For

This is for engineers who:

  • know why IEEE754 is insufficient for finance
  • have debugged rounding errors at 3am
  • care about reproducibility under audit
  • build systems where mistakes cost real money

If you’re building:

  • low-latency trading infra
  • accounting engines
  • blockchain / DeFi protocols
  • risk or pricing systems

Development

cmake -DCMAKE_BUILD_TYPE=Debug -Dlibdecimal_BUILD_TESTS=ON -S . -B build # configure (debug + tests)
cmake --build build --parallel                                           # build everything
cd build && ctest --output-on-failure                                    # run tests
cmake --build build --target docs_build                                  # install mkdocs locally
cmake --build build --target docs_serve                                  # run webserver @ http://127.0.0.1:9000/

Installation

sudo apt install build-essential cmake
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake --build build --parallel
sudo cmake --install build

Usage

After installation, libdecimal is available as a standard CMake package:

find_package(libdecimal REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE libdecimal::libdecimal)

Attribution

LIBDECIMAL builds on Intel’s LIBBID implementation of IEEE 754 decimal arithmetic. The heavy lifting — the arithmetic itself — comes from the work of Marius Cornea, John Harrison, Cristina Anderson, and Evgeny Gvozdev. The underlying model traces back to Mike Cowlishaw and the IEEE 754 standard.

The template/macro contraption that makes it usable in modern C++, along with the full decomposition of BID into sign, significand, and exponent — that is on me.

About

A modern C++23 header-only library for IEEE-754 decimal floating-point arithmetic, built on Intel’s BID implementation.

Resources

License

Stars

Watchers

Forks

Packages