I am trying to write a very efficient C++ class that defines a new floating point type with much more precision than the primitive data types. See my previous post for more background.
To start I am using static allocation in my hp_float.hpp
:
class hp_float {
private:
unsigned char buf[48];
public:
hp_float();
hp_float operator+(const hp_float& h);
};
My problem is that, eventually, in order to implement that operator+
I am going to have to use bit-wise operations including <<
and >>
. I saw that this can be tricky with these buffers, as seen in this SO post.
I would like to do shifting without the need for a loop. I could manually unroll it in my implementation, but ultimately I want to treat the buffer as a contiguous string of bits like any other primitive data type:
hp_float hp_float::operator+(const hp_float& h) {
[type???] this_sign = buf >> (48*8-1);
...
}
My Question: Is this not possible? Do have any advice one doing what I want with the best performance?