views:

348

answers:

3

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?

+1  A: 

I think this one is quite good for most purposes: http://www.trenki.net/content/view/17/1/

It's quite lightweight and fast and supports some basic mathematics (multiplication, division, inversion, sin, cos, sqrt, rsqrt).

kotlinski
A: 

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

PeterK
Nice libraries, good C++ bindings. But both support just big ints, rationals and big floats: I don't think either support fixed point.
Charles Stewart
My bad, i mistakenly thought you meant "floating" point. I should read the question more carefully in the future. Sorry.
PeterK
A: 

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

mtrw