- Notifications
You must be signed in to change notification settings - Fork94
C++ header-only fixed-point math library
License
MikeLankamp/fpm
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A C++ header-only fixed-point math library. "fpm" stands for "fixed-point math".
It is designed to serve as a drop-in replacement for floating-point types and aims to provide as much of the standard library's functionality as possible with exclusively integers.fpm requires C++11 or higher.
fpm is designed to guard against accidental conversion to and from floats and supports many of the standard C++ maths functions, including trigonometry, power and logarithmic functions, with performance and accuracy generally comparable to alternative libraries.
There are several reasons why you can not or choose not to use floating-point math, but still want a similar type:
- Your target platform lacks an FPU, does not support floating-point operations or its floating-point operations areconsiderably slower than fixed-point integer operations.
- You require deterministic calculations.
If any of these reasons apply for you, and your problem domain has a clearly outlined range and required resolution,then fixed-point numbers might be a solution for you.
To usefpm, include its header<fpm/fixed.hpp> and use thefpm::fixed_16_16,fpm::fixed_24_8 orfpm::fixed_8_24types as if they were native floating-pointer types:
#include<fpm/fixed.hpp>// For fpm::fixed_16_16#include<fpm/math.hpp>// For fpm::cos#include<fpm/ios.hpp>// For fpm::operator<<#include<iostream>// For std::cin, std::coutintmain() { std::cout <<"Please input a number:"; fpm::fixed_16_16 x; std::cin >> x; std::cout <<"The cosine of" << x <<" radians is:" <<cos(x) << std::endl;return0;}
To use the fixed-point equivalents of the<math.h> functions such assqrt,sin andlog, include the header<fpm/math.hpp>.To stream fixed-point values to or from streams, include the header<fpm/ios.hpp>.
Please refer to thedocumentation for detailed information how to usefpm, or skip straight to theperformance oraccuracy results.
This library is a work-in-progress. We welcome any contributions that improve the functional coverage or the performance or accuracy of the mathematical functions.
See theLICENSE file
About
C++ header-only fixed-point math library
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.