libfxd 0.2.dev
A fixed-point library for C++.
Loading...
Searching...
No Matches
Introduction

libfxd is a C++20 headers-only library that implements fixed-point types as a templated class. It's licensed under the Apache Public License 2.0.

Quick example

#include <iostream>
#include <fxd/fxd.hpp> // include everything
int main()
{
using F = fxd::fixed<20, 12>;
F a = 5; // construct from integer
F b = 2.5; // construct from floating point
F c; // uninitialized
std::cout << "Enter a value: ";
std::cin >> c;
F d = (a + b + c) / 3;
std::cout << "Average: " << d << std::endl;
std::cout << "which has raw value: " << d.raw_value << std::endl;
using F2 = fxd::fixed<10, 10>;
auto x = a < F2{5};
std::cout << x << std::endl;
}
Includes all of libfxd headers.
The fixed-point class template.
Definition: fixed.hpp:38
raw_type raw_value
The raw value, stored as a bitfield.
Definition: fixed.hpp:65

Installation

Since it's a headers-only library, no compilation is necessary; the compiler just needs to locate the headers using an option like -I /path/to/libfxd/include.

To install the headers, use the standard Automake procedure:

./configure --prefix=/usr
make
sudo make install

See the INSTALL file and/or run ./configure --help for more details.

If the source code was checked out from the repository, you may need to first run the bootstrap script to create the configure script.