Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ fixed point library? [closed]

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

  • No unnecessary runtime overhead: whatever can be done at compile time, should be done at compile time.
  • Ability to transparently switch code between fixed and floating point, with no inherent overhead.
  • Fixed point math functions. There's no much point using fixed point if you need to cast back and forth in order to take a square root.
  • Small footprint.

Any suggestions?

like image 872
uj2 Avatar asked May 31 '10 20:05

uj2


People also ask

What is fixed-point in C?

Fixed-point math typically takes the form of a larger integer number, for instance 16 bits, where the most significant eight bits are the integer part and the least significant eight bits are the fractional part.

How do you do fixed-point division?

To divide two fixed-point numbers, one takes the integer quotient of their underlying integers, and assumes that the scaling factor is the quotient of their scaling factors. In general, the first division requires rounding and therefore the result is not exact.

What is floating point and fixed-point?

A fixed point number just means that there are a fixed number of digits after the decimal point. A floating point number allows for a varying number of digits after the decimal point. For example, if you have a way of storing numbers that requires exactly four digits after the decimal point, then it is fixed point.

What is fixed-point multiplication?

To perform fixed-point multiplication, we can first ignore the binary point of the multiplier and multiplicand, perform the multiplication treating the operands as two's complement numbers, and, then, determine the position of the binary point for the result.


1 Answers

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

  • libfixmath Project Page
  • libfixmath Wikipedia Article

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

like image 83
flatmush Avatar answered Oct 02 '22 15:10

flatmush