calx
C++23 Comprehensive Math Library
C++23 / LGPL v3 / Zero External Dependenciescalx is a C++23 math library that provides arbitrary-precision arithmetic (Int, Float, Rational), complex numbers, polynomials, matrices, special functions, FFT, and Lie groups within a single unified framework.
The name derives from the Latin calculus (pebble — the etymological root of "calculation").
Arbitrary Precision
Three core types: Int (integer), Float (floating-point), and Rational. High-speed mpn operations via BMI2/ADX instructions, with a 5-tier multiplication pipeline (Basecase → Karatsuba → Toom-3 → Toom-4 → NTT).
NaN / Infinity Safe
NaN and Infinity propagate safely across Int, Float, and Rational. Division by zero never crashes.
C++23 Concepts
Defines 50+ algebraic concepts such as Ring, Field, and VectorSpace. Write type-safe generic algorithms with compile-time guarantees.
80+ Special Functions
Bessel, Airy, Gamma, Zeta, elliptic integrals, hypergeometric functions, and more.
Available for double, Complex<double>, and Float (arbitrary precision).
Numerical Algorithms
Linear algebra (LU/QR/SVD), root-finding, interpolation, and FFT.
Combine freely with arbitrary-precision types, e.g. Matrix<Float>.
Lie Groups / Algebras
SO(2), SE(2), SO(3), SE(3) with exp/log, Jacobians, and adjoint representations. Left-perturbation model (GTSAM convention).
API Reference
Core Types (Compiled Library)
Core Types (Header-Only)
Algorithm Modules (Header-Only)
Algorithm Details
In-depth explanations of the algorithms used internally. Covers thresholds, computational complexity, and design rationale.
Demos
Working examples using calx features. Includes source code — build and run locally.
Examples
Int — Arbitrary-Precision Integer
#include <math/core/mp/Int.hpp>
#include <iostream>
using namespace calx;
int main() {
Int a("123456789012345678901234567890");
Int b("987654321098765432109876543210");
std::cout << "a + b = " << a + b << std::endl;
std::cout << "a * b = " << a * b << std::endl;
std::cout << "gcd = " << gcd(a, b) << std::endl;
// Primality test (Miller-Rabin)
Int p("170141183460469231731687303715884105727"); // 2^127 - 1
std::cout << p << " is prime: " << std::boolalpha
<< isProbablePrime(p) << std::endl;
// NaN/Infinity safe propagation
Int zero;
Int nan = Int(1) / zero;
std::cout << "1/0 = " << nan << std::endl; // NaN
}
Float — Arbitrary-Precision Floating-Point
#include <math/core/mp/Float.hpp>
#include <iostream>
using namespace calx;
int main() {
int prec = 50; // 50-digit precision
Float::setDefaultPrecision(prec);
// Mathematical constants (thread-local cached; instant on subsequent calls)
Float pi = Float::pi(prec); // π to 50 digits (Chudnovsky)
// Transcendental functions
Float y = exp(pi, prec); // e^π
Float z = log(y, prec); // log(e^π) = π
std::cout << "exp(pi) = " << y.toDecimalString(prec) << std::endl;
std::cout << "log(exp(pi)) = " << z.toDecimalString(prec) << std::endl;
// Trigonometric functions
Float s = sin(pi / Float(6, prec), prec); // sin(π/6) = 0.5
std::cout << "sin(pi/6) = " << s.toDecimalString(20) << std::endl;
}
Rational — Arbitrary-Precision Rational Number
#include <math/core/mp/Rational.hpp>
#include <iostream>
using namespace calx;
int main() {
Rational a(1, 3); // 1/3
Rational b(1, 6); // 1/6
Rational sum = a + b;
std::cout << "1/3 + 1/6 = " << sum << std::endl; // 1/2 (auto-reduced)
Rational product = a * b;
std::cout << "1/3 * 1/6 = " << product << std::endl; // 1/18
// Combine with arbitrary-precision integers
Rational big(Int("1000000000000000000"), Int("3"));
std::cout << big << std::endl;
}
Vector — Numeric Vector
#include <math/core/vector.hpp>
#include <iostream>
using namespace calx;
int main() {
Vector<double> a{1.0, 2.0, 3.0};
Vector<double> b{4.0, 5.0, 6.0};
// Expression templates: no temporaries until assignment
Vector<double> c = 2.0 * a + b;
std::cout << "dot(a, b) = " << dot(a, b) << std::endl; // 32
std::cout << "norm(a) = " << norm(a) << std::endl; // 3.74166
// 3D cross product (StaticVector)
StaticVector<double, 3> i{1, 0, 0}, j{0, 1, 0};
auto k = cross(i, j); // [0, 0, 1]
}
Build
Requirements
- C++23 compatible compiler (tested with MSVC 17.x / Visual Studio 2022)
- 64-bit OS (x86_64 / AArch64)
- CMake 3.20 or later
Supported Platforms and Performance
calx requires a 64-bit (x86_64 / AArch64) environment.
The internal arbitrary-precision arithmetic relies on 64-bit limbs and 128-bit wide multiplication (_umul128 / __uint128_t), so 32-bit platforms are not supported.
The following hardware features are automatically utilized when available:
| Fast Path | Enabled When | Fallback |
|---|---|---|
| AVX2 NTT Butterfly | AVX2-capable CPU (Intel Haswell+ / AMD Zen+) | Scalar Montgomery NTT |
| MULX/ADCX/ADOX mpn Primitives |
BMI2 + ADX CPU, x64 Windows (MASM) | C++ generic implementation |
| NTT Parallelization | NTT length ≥ 4096 (auto-detected) | Single-threaded |
- Windows x64 + AVX2: All fast paths enabled. Best performance.
- Linux x64 + AVX2: AVX2 NTT enabled. MASM assembly disabled (mpn primitives fall back to C++).
- ARM / Apple Silicon: AVX2 and MASM both disabled. All features work, but arbitrary-precision throughput is reduced.
Download
The current release includes Int (arbitrary-precision integer), Float (arbitrary-precision floating-point), Rational (rational number), and Vector (numeric vector).
Pre-built Binary (Recommended)
Headers and pre-built DLL. No build required — ready to use immediately.
Download calx-dll-2026.04.03a.zip (DLL)
Quick test — create this minimal myapp.cpp to verify the DLL links correctly:
// myapp.cpp
#include <math/core/mp/Int.hpp>
#include <iostream>
using namespace calx;
int main() {
Int a = Int::factorial(100);
std::cout << "100! = " << a << std::endl;
}
After extracting the zip, compile and run from the command prompt:
REM 1. Compile (replace C:\path\to\calx with your extraction path)
cl /std:c++23 /EHsc /utf-8 /I C:\path\to\calx\include myapp.cpp C:\path\to\calx\lib\calx_core.lib
REM 2. Copy DLL next to exe and run
copy C:\path\to\calx\lib\calx_core.dll .
myapp.exe
Building and Running the Included Examples (DLL)
The zip includes sample source code and a CMakeLists.txt. To build all examples at once:
cd calx
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
After building, run the sample programs from the console:
Release\example_int.exe
Release\example_float.exe
Release\example_rational.exe
Release\example_vector.exe
Release\example_matrix.exe
Release\example_linalg.exe
Release\example_precision_showdown.exe
Release\example_mp.exe
Release\example_int_demo.exe
Release\example_float_demo.exe
Release\example_rational_demo.exe
Release\example_vector_demo.exe
Antivirus False Positive Warning (DLL version)
calx_core.dll may be falsely flagged and quarantined
by antivirus software (McAfee, Windows Defender, Norton, etc.).
The DLL always contains modular exponentiation (Montgomery multiplication) and MASM assembly kernels,
so it may be flagged even if your code does not use powMod or other cryptographic operations.
The DLL may be quarantined at the moment the zip is extracted. Quarantine happens silently and may be reported with a delay, making it appear as though the DLL is missing.
If blocked, add calx_core.dll to your antivirus exclusion list.
This issue affects not only calx sample programs but also
your own applications that link against calx.
Other cryptographic and arbitrary-precision libraries such as GMP and OpenSSL are also affected by the same issue.
Source Code
Download the source if you want to build it yourself.
Download calx-source-2026.04.03a.zip (Source)
You can also browse individual files from the source listing.
Building from Source (Source version only)
cd calx
mkdir build
cd build
cmake .. -G "Visual Studio 17 2022" -A x64
cmake --build . --config Release
This generates calx.sln and per-target .vcxproj files in the build/ directory.
Running the Examples
After building, run the sample programs from the console:
examples\Release\example-int.exe
examples\Release\example-float.exe
examples\Release\example-rational.exe
examples\Release\example-vector.exe
examples\Release\example-matrix.exe
examples\Release\example-linalg.exe
examples\Release\example-precision-showdown.exe
examples\Release\example-mp.exe
examples\Release\example-int-demo.exe
examples\Release\example-float-demo.exe
examples\Release\example-rational-demo.exe
examples\Release\example-vector-demo.exe
Antivirus False Positive Warning (Source version)
Executables built from source may be falsely flagged as malware by antivirus software.
calx_int.lib contains modular exponentiation (Montgomery multiplication) and MASM assembly kernels,
which are statically linked into your executable.
Even programs that do not call powMod or other cryptographic functions may be flagged
if the linker's unused code elimination (/OPT:REF) does not remove these symbols.
Release builds typically eliminate unused code, making detection less likely; Debug builds are more susceptible.
Quarantine happens silently and may be reported with a delay, making it appear as though the build failed and no exe was generated. If blocked, add your build directory to your antivirus exclusion list.
Other cryptographic and arbitrary-precision libraries such as GMP and OpenSSL are also affected by the same issue.
Release History
| 2026-03-27 | Vector released + English translations |
| 2026-03-23 | Pre-built DLL distribution started |
| 2026-03-20 | Rational released |
| 2026-03-13 | Float released |
| 2026-03-02 | Int released (initial release) |