GithubHelp home page GithubHelp logo

carbone13 / fpm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikelankamp/fpm

0.0 0.0 0.0 453 KB

C++ header-only fixed-point math library

Home Page: https://mikelankamp.github.io/fpm

License: MIT License

C++ 93.32% Python 1.33% Gnuplot 0.74% CMake 4.61%

fpm's Introduction

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 Build 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 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 <fpm/fixed.hpp> 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:

#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::cout

int 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 <math.h> functions such as sqrt, sin and log, 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 the documentation for detailed information how to use fpm, or skip straight to the performance or accuracy 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 file

fpm's People

Contributors

mikelankamp avatar bigbadboris avatar eren121 avatar flaviut avatar klummel69 avatar carbone13 avatar matwey avatar notcamelcase avatar haberturdeur avatar j-jorge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.