Boost logo

Boost :

Subject: [boost] Interest for a Fixed Point Arithmetics library
From: Julien Vernay (julienvernay99_at_[hidden])
Date: 2017-12-30 18:29:33

Hello everybody.
I am working on a project that needs and can use fixed point numbers, so I
started searching for a library implementing fixed point numbers, but I
didn't find anything. So I was wondering if people would need fixed point
arithmetics, and here I am.

The aim of this FixedPointNumber is to fix the point at compile-time using
template, and having another template argument for the underlying type.
So we have :

    template<typename T, size_t N>
    class FixedPointNumber {
        T value;

The N last bits of value is the decimal part : so to convert a
FixedPointNumber to an int, we need only to use a bitshift operator (and
same for construction from int).
sizeof(FixedPointNumber<T,N>) == sizeof(T) , so there is no overhead in
this implementation.
Arithmetic and relational operators will be implemented.
Multiplication needs one int multiplication and one bit shift.
Division needs one int division and one bit shift.
There is only one value for zero.
Sign can be extracted with Most Significant Bit.

I have already a basic implementation but if it interests more people I
will do a proper implementation.

Thank you for reading !

Boost list run by bdawes at, gregod at, cpdaniel at, john at