libdecimal is a header-only C++ library for IEEE 754-2008 decimal floating-point arithmetic, built on Intel's LIBBID reference implementation. It wraps the BID (binary-integer-decimal) encoding in a typed, constexpr-friendly interface with exact base-10 semantics and deterministic cross-platform results. Decimal32 / Decimal64 / Decimal128 are supported, together with transcendental functions, string and binary-float conversions, and full decomposition into sign, significand, and exponent — plus direct access to the underlying BID bit patterns for interop and persistence. Lightweight fixed-point, scaled-integer, and BCD representations are also included.
| Layer | Role |
|---|---|
| libdecimal | Header-only C++ decimal arithmetic interface |
| Intel LIBBID | Vendored IEEE 754 decimal (BID) reference implementation |
| OS / Compiler | GCC 13 | GCC 14 | GCC 15 | Clang 17 | Clang 18 | Clang 19 | Clang 20 | Apple Clang | MSVC |
|---|---|---|---|---|---|---|---|---|---|
| Ubuntu 22.04 | |||||||||
| Ubuntu 24.04 | |||||||||
| macOS 14 | |||||||||
| Windows |
macOS is built for x86_64 and exercised under Rosetta 2: Intel's float128 (DPML) sources are x86_64-only, so libdecimal targets amd64 / x86_64 on every platform.
Native installers are attached to each tagged release. All packages are x86_64 / amd64 (Intel's DPML is x86_64-only).
| Platform | Package |
|---|---|
| Debian / Ubuntu (amd64) | libdecimal-2.2.3-Linux-amd64.deb |
| Red Hat / Fedora (x86_64) | libdecimal-2.2.3-Linux-x86_64.rpm |
| macOS (x86_64) | libdecimal-2.2.3-macOS-x86_64.pkg |
| Windows (x64) | libdecimal-2.2.3-Windows-x64.exe |
Download them from the Releases page. Each installer ships the headers, the Intel LIBBID static library, and the libdecimal CMake package files.
| Requirement | Minimum | Tested ceiling |
|---|---|---|
| C++ standard | C++23 | C++23 |
| CMake | 3.22 | — |
| Toolchains | GCC 13 · Clang 18 · Apple Clang · MSVC 19.4x | GCC 14 · Clang 20 |
find_package(libdecimal REQUIRED)
add_executable(app main.cpp)
target_link_libraries(app PRIVATE libdecimal::libdecimal)#include <decimal/bid.hpp>
#include <iostream>
int main() {
using namespace math::literals;
math::decimal_t<uint64_t> price(12345, -2); // 123.45
math::decimal_t<uint64_t> fee_rate = 0.0025_dec; // 0.25 %
auto fee = price * fee_rate;
auto total = price + fee;
std::cout << "price: " << price << " fee: " << fee << " total: " << total << '\n';
std::cout << "exp(price): " << math::exp(price) << '\n'; // transcendentals on the BID path
}cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel
sudo cmake --install buildThe only build artifact is the vendored Intel LIBBID static library (libbid_static); everything libdecimal adds is header-only.
The examples/ directory contains standalone programs demonstrating each representation:
| File | Representation |
|---|---|
examples/bid_example.cpp |
IEEE 754 BID via Intel LIBBID |
examples/fixed_example.cpp |
Compile-time fixed-point |
examples/bcd_example.cpp |
Binary-coded decimal |
examples/scaled_example.cpp |
Lightweight scaled-integer pair |
cmake -S . -B build -Dlibdecimal_BUILD_EXAMPLES=ON
cmake --build build --parallel
./build/bid_examplecmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -Dlibdecimal_BUILD_TESTS=ON # configure (debug + tests)
cmake --build build --parallel # build everything
ctest --test-dir build --output-on-failure # run the test suite
cmake --build build --target docs_serve # serve docs @ http://127.0.0.1:9000/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 layer that makes it usable in modern C++, along with the full decomposition of BID into sign, significand, and exponent, is the contribution of this project.