Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

C++ header-only fixed-point math library

License

NotificationsYou must be signed in to change notification settings

MikeLankamp/fpm

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.

Build StatusBuild status

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 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.

Quick Start

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>.

Documentation

Please refer to thedocumentation for detailed information how to usefpm, or skip straight to theperformance oraccuracy 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 theLICENSE file

About

C++ header-only fixed-point math library

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp