- Cross-platform library with support for GCC, Cland and MSVC.
- Modern C++23
- Competitive performance (see library comparisons).
- Linear algebra types: vectors, matrices, quaternions, and normals.
- 3D graphics suitable types: bound boxes, projection matrices, camera, color.
- Type safety: correct unit conversions, transformation matrices, and normalization.
- Safe by default with explicit faster options.
- Debug visualizers for all types (MSVC (ready) and GDB (coming soon)).
- Printing types using
std::ostreamorstd::format. - Useful utilities.
Vcfor simd wrappersGoogle Testfor tests onlyGoogle Benchmarkfor benchmarks only
For functionality and usage examples see usage.
Using CPM.cmake:
CPMAddPackage("gh:4J-company/mr-math#master")
target_link_libraries(<your-project>
PUBLIC/INTERFACE/PRIVATE
mr-math-lib)Add special 4j remote to your machine:
git clone https://github.com/4J-company/conan-center-index.git cci-4j
conan remote add 4J-company ./cci-4j --type local-recipes-indexAdd "mr-math/1.1.0" to your conanfile.
Build with Conan:
conan build . -b missing -o target=alltarget option controls which CMake targets are built. Possile values are library (default), tests, benchmark, or all.
For other options, see conanfile.py.
Once you installed all dependencies with Conan, you can build with CMake:
cmake --preset <preset-name>
cmake --build --preset <preset-name>CMake presets are generated by Conan depending on your configuration. To see available presets, run:
cmake --list-presetsbash run-bench-viz.shThis generates a plot with the benchmarking results
NOTE: requires python, pandas, matplotlib, numpy
conan build . -b missing -o '&:target=bench'cmake -DMR_MATH_ENABLE_BENCHMARK=ON -DMAKE_BUILD_TYPE=Release
cmake --build build/benchmark
./build/benchmark/mr-math-benchIf you are interested in specific results, you can disable particular benchmarks with the following options:
MR_MATH_ENABLE_VEC_BENCHMR_MATH_ENABLE_MATR_BENCHMR_MATH_ENABLE_QUAT_BENCHMR_MATH_ENABLE_AABB_BENCHMR_MATH_ENABLE_CAM_BENCHMR_MATH_ENABLE_COLOR_BENCH
To enable extra optimizations use:
MR_MATH_EXTRA_OPTIMIZED
Adds-ffast-math, this hurts accuracy a little but increases perf a lotMR_MATH_ENABLE_PROFILING
Makes changes suggested by profiling tools used by me
Adds-lprofiler -ltcmalloc
DOES NOT include any optimization
| Library | Matrix Multiplication (ns) | Vector normalization (ns) | Scalar triple products (ns) |
|---|---|---|---|
| mr. Math | 4 | 2 | 6.5 |
| DirectXMath | 4.8 | 4.3 | 2.3 |
| glm | 5.7 | 3.3 | 1.6 |
| cglm | 6.2 | 14.6 | 2.2 |
| lin | 5.7 | 3.3 | 2.3 |