Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MikeLankamp/fpm
C++ header-only fixed-point math library
https://github.com/MikeLankamp/fpm
cxx11 deterministic fixed-point header-only maths
Last synced: 3 months ago
JSON representation
C++ header-only fixed-point math library
- Host: GitHub
- URL: https://github.com/MikeLankamp/fpm
- Owner: MikeLankamp
- License: mit
- Created: 2019-01-16T20:03:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-09T21:41:56.000Z (6 months ago)
- Last Synced: 2024-05-15T18:14:38.001Z (6 months ago)
- Topics: cxx11, deterministic, fixed-point, header-only, maths
- Language: C++
- Homepage: https://mikelankamp.github.io/fpm
- Size: 444 KB
- Stars: 600
- Watchers: 20
- Forks: 73
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-embedded-software - FPM - C++ header-only fixed-point math library. (Data processing / Math)
README
# fpm
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.
[![Build Status](https://travis-ci.org/MikeLankamp/fpm.svg?branch=master)](https://travis-ci.org/MikeLankamp/fpm)
[![Build status](https://ci.appveyor.com/api/projects/status/0velpwqk38spu412?svg=true)](https://ci.appveyor.com/project/MikeLankamp/fpm)`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.
## Why use fixed-point math?
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 are
considerably 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.## Quick Start
To use `fpm`, include its header `` and use the `fpm::fixed_16_16`, `fpm::fixed_24_8` or `fpm::fixed_8_24`
types as if they were native floating-pointer types:
```c++
#include // For fpm::fixed_16_16
#include // For fpm::cos
#include // For fpm::operator<<
#include // For std::cin, std::coutint main() {
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;
return 0;
}
```To use the fixed-point equivalents of the `` functions such as `sqrt`, `sin` and `log`, include the header ``.
To stream fixed-point values to or from streams, include the header ``.## Documentation
Please refer to the [documentation](docs/index.md) for detailed information how to use `fpm`, or skip straight to the [performance](docs/performance.md) or [accuracy](docs/accuracy.md) results.## Contributions
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.## License
See the [LICENSE](LICENSE) file