What i need is a C++ library (preferably C++, C will do as well) that implements any sort of decimal number - be they floating-point or not.
My requirements in terms of precision are rather humble - max of 10 digits after the point, and at least 20 digits before (i.e., {20digits}.{10digits}. The bottleneck in my case is space and efficiency - there will be an enormous amount of decimals (probably in the count of hundreds of millions) that i need to store and do operations on. There's also a need for storing them in files as well, so the ABI should be stable as well; or at least there should be an ability to extract the underlying parts (e.g., mantissa+exponent in case of floating-point).
I guess that implementation using int128 and fixed point at the 10th digit would suit me, though i would rather not implement it myself. However, if i need to, i don't mind doing so, in which case any related libraries that would help me implement arithmetic (and in the future, probably more advanced) operations would also be welcome.
Ive already looked into boost::multiprecision and libmpdec but they both allocate memory. libmpdec can be configured to only use statically allocated decimals, but there is still a problem of mpd_t structure being huge (48 bytes, i think).
PICTURE IS 9(20)V9(10)
to pack two decimal digits into each byte. And buy yourself an IBM mainframe to run it on, as it has packed decimal hardware to do the operations in one machine instruction. Some things were actually a lot easier in the good old days. I still miss the power ofADD CORRESPONDING
. :-)