C ++ fixed point library?

I am looking for a free C ++ library with a fixed point (mainly for use with embedded devices, and not for arbitrary precision maths). Basically, the requirements are:

  • No overhead at runtime: everything that can be done at compile time must be done at compile time.
  • The ability to transparently switch code between fixed and floating point without any overhead.
  • Fixed point math functions. It makes no sense to use a fixed point if you need to cast back and forth to get a square root.
  • Small size.

Any suggestions?

+49
c ++ math fixed-point
May 31 '10 at 20:01
source share
7 answers

There is an open source fixed point library project that can be found at the links below:

This is a static C library with a C ++ class interface for C ++ users, it implements the following functions: Trigonometric 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 data types .

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

+6
Mar 02 '11 at 17:14
source share

Check out two good options for implementing fixed-point processing in C ++ (no external libraries required).

  • Fixed-Point-Class by Peter Schregle. It also effectively implements basic operations such as 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); } 
  • Implementation of fixed-point numbers in C ++ by Khuram Ali.

+5
Jan 14 '14 at 10:51
source share

I will try the http://www.efgh.com/software/fixed.htm tiny library ...

+1
Jan 04 2018-11-12T00:
source share

I have a nice little C ++ header. You can find it under sweet :: Fixed . Just define typedef sweet :: Fixed MyFloat; and use it like any other float value. Or replace it with any kind of floating type. The class has two 64-bit values. One for the integer part and 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 
+1
Jan 14 '14 at 10:37
source share

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

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

It supports 32-bit and 64-bit fixed-point numbers (with an arbitrary coefficient) and both fast (all patterns, but slightly more manual) and slow fixed-point numbers (more automatic, but slow).

It focuses on embedded platforms, but I used it on both microcontrollers and Linux without any problems.

+1
Mar 04 '15 at 23:35
source share

Perhaps you could try the GMP or MPFR libraries. I am sure that they will satisfy your productivity needs, but maybe they are too much for your needs and you need something easier. Anyway, look here:

GMP library

or here:

MPFR library

-3
May 31 '10 at 20:36
source share

I have never used SPUC , but the description covers fixed-point data types and some mathematical functions.

-3
May 31 '10 at 20:37
source share



All Articles