Description
Arithmetic operations in C++ are NOT guaranteed to yield a correct mathematical result. This feature is inherited from the early days of C. The behavior of int, unsigned int and others were designed to map closely to the underlying hardware. Computer hardware implements these types as a fixed number of bits. When the result of arithmetic operations exceeds this number of bits, the result is undefined and usually not what the programmer intended. It is incumbent upon the C++ programmer to guarantee that this behavior does not result in incorrect behavior of the program. This library implements special versions of these data types which behave exactly like the original ones EXCEPT that the results of these operations are checked to be sure that an exception will be thrown anytime an attempt is made to store the result of an undefined operation.
Note: This is the subject of a various presentations at CPPCon.
The first one is a short version which gives the main motivation for the librar
safe_numerics alternatives and similar libraries
Based on the "Math" category.
Alternatively, view safe_numerics alternatives based on common mentions on social networks and blogs.
-
Eigen
A high-level C++ library of template headers for linear algebra, matrix and vector operations, numerical solvers and related algorithms. [MPL2] -
TinyExpr
tiny recursive descent expression parser, compiler, and evaluation engine for math expressions -
MIRACL
MIRACL Cryptographic SDK: Multiprecision Integer and Rational Arithmetic Cryptographic Library is a C software library that is widely regarded by developers as the gold standard open source SDK for elliptic curve cryptography (ECC). -
linmath.h
a lean linear math library, aimed at graphics programming. Supports vec3, vec4, mat4x4 and quaternions -
ExprTK
C++ Mathematical Expression Parsing And Evaluation Library https://www.partow.net/programming/exprtk/index.html -
NT2
DISCONTINUED. A SIMD-optimized numerical template library that provides an interface with MATLAB-like syntax. [Boost] -
LibTomMath
LibTomMath is a free open source portable number theoretic multiple-precision integer library written entirely in C. -
Xerus
A general purpose library for numerical calculations with higher order tensors, Tensor-Train Decompositions / Matrix Product States and other Tensor Networks -
SLIMCPP
Simple Long Integer Math for C++. Lightweight cross-platform header-only library what implements big integer arithmetic in С++17. -
Mission : Impossible (AutoDiff)
A concise C++17 implementation of automatic differentiation (operator overloading) -
Armadillo
A high quality C++ linear algebra library, aiming towards a good balance between speed and ease of use. The syntax (API) is deliberately similar to Matlab. [MPL2] -
GMP
A C/C++ library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. [LGPL3 & GPL2]
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of safe_numerics or a related project?
README
safe_numerics
Arithmetic operations in C++ are NOT guaranteed to yield a correct mathematical result. This feature is inherited from the early days of C. The behavior of int, unsigned int and others were designed to map closely to the underlying hardware. Computer hardware implements these types as a fixed number of bits. When the result of arithmetic operations exceeds this number of bits, the result is undefined and usually not what the programmer intended. It is incumbent upon the C++ programmer to guarantee that this behavior does not result in incorrect behavior of the program. This library implements special versions of these data types which behave exactly like the original ones EXCEPT that the results of these operations are checked to be sure that an exception will be thrown anytime an attempt is made to store the result of an undefined operation.
Note: This is the subject of a various presentations at CPPCon.
The first one is a short version which gives the main motivation for the library with a rowsing sales pitch. Fun and suitable for upper management. https://www.youtube.com/watch?v=cw_8QkFXZjI&t=1s
The second is more extensive in that it addresses a real world case study which touches on most of the important aspects of the libary. https://www.youtube.com/watch?v=93Cjg42bGEw .
Finally, for those who still enjoy the written word there is the documentation in which significant effort has been invested. http://htmlpreview.github.io/?https://github.com/robertramey/safe_numerics/master/doc/html/index.html
If you use this libary and find it useful, please add a star. I need motivation!!!