C++ fixed point library? [closed]

烂漫一生 提交于 2019-11-27 06:20:37
flatmush

There is an open-source fixed point math library project which can be found by following the links below:

It is a C static library with a C++ class interface for C++ users, it implements the following functionality: Trig. Functions: sin, cos, tan, asin, acos, atan, atan2 Saturated Arithmetic: sadd, ssub, smul, sdiv Other Functions: sqrt, exp

It only supports 16.16 fixed-point datatype.

It is an actively developed open-source project (looking for interested developers).

Check out the following two good implementations about handling fixed point representation in C++ (no external libs are needed).

  1. Fixed-Point-Class by Peter Schregle. It also efficiently implements the basic operations like addition, multiplication, and division.

    Code example:

    #include <fixed_point.h>
    using namespace fpml;
    
    main()
    {
        fixed_point<int, 16> a = 256;
        fixed_point<int, 16> b = sqrt(a);
    }
    
  2. Implementing Fixed-Point Numbers in C++ by Khuram Ali.

Here is an open source fixed-point library on GitHub:

https://github.com/mbedded-ninja/MFixedPoint

It supports 32-bit and 64-bit fixed-point numbers (with a arbitrary quotient) and both fast (everything is templated, but a little more manual) and slow fixed-point numbers (more automatic, but slower).

It is geared towards embedded platforms, however I have used it on both microcontrollers and Linux without any issues.

burner

I got a nice little c++ header. You can find it under sweet::Fixed. Simply define typedef sweet::Fixed MyFloat; and use it like any other float value. Or exchange it whatever float type you want later. The class has two 64 bit values. One for the integer part and on for the fraction.

I have a small fixed point c++11 class header impl in sweet.hpp called fixed.hpp. It uses 32bit for both parts.

typedef float MyFloat;         // This will feel the same
typedef sweet::Fixed MyFloat;  // like this

Maybe you could try the GMP or MPFR libraries. I'm quite sure they will satisfy your performance needs, but maybe they are too much for your needs and you want something more lightweight. Anyway, look here:

GMP library

or here:

MPFR library

I haven't ever used SPUC, but the description claims fixed-point data types and some math functions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!