fxmath is a header-only C++ library for performing mathematical operations in simulated low-precision environments using FloatX. It replicates nearly all functionality of the C/C++ standard library's math.h or <cmath> headers, allowing users to conduct low-precision numerical experiments seamlessly. This makes it ideal for research and applications in numerical analysis, machine learning, and energy-efficient computing.
- Full support for mathematical operations simulated in low precisions as defined by FloatX.
- Covers most functions from the C/C++ standard library's
math.h/<cmath>. - Designed for easy integration with existing projects requiring custom precision simulations.
- Lightweight and easy to use.
fxmath implements most of the functions in math.h/<cmath>:
- Basic Arithmetic:
fabs,fmod,remainder,ceil,floor,round - Exponential and Logarithmic:
exp,log,log10,log2,pow - Trigonometric:
sin,cos,tan,asin,acos,atan,atan2 - Hyperbolic:
sinh,cosh,tanh,asinh,acosh,atanh - Special Functions:
sqrt,cbrt,hypot - Error and Gamma Functions:
erf,erfc,tgamma,lgamma
One can use these functions simply by adding the prefix "fx_" to the function names. All function instructions follows math functions except the float numbers are replaced with floatx numbers.
FloatX: fxmath relies on the FloatX library to define and handle custom low-precision floating-point types. You can find and install FloatX from its GitHub repository.
Clone the repository:
git clone https://github.com/chenxinye/fxmath.git
cd fxmathBuild and integrate fxmath into your project:
makeOr include it directly in your codebase by adding the relevant files.
-
Include fxmath in your project:
#include <fxmath.hpp>
-
Set up FloatX types and Perform mathematical operations: Define custom low-precision floating-point types using FloatX.
#include <floatx.hpp> using fx8 = flx::floatx<8, 23>; // Define a FloatX type (8-bit exponent, 23-bit mantissa) ```cpp fx8 a = 3.14; fx8 b = fxmath::fx_sin(a);
More examples can be viewed at inside the folder ''examples''.
- The repo is supported by FloatX library for enabling customizable low-precision floating-point arithmetic.