Say I have this number:
// bmp = boost::multiprecision
bmp::cpp_dec_float n("123456789.1234567891011121314");
its backend data are:
[0] 1 unsigned int
[1] 23456789 unsigned int
[2] 12345678 unsigned int
[3] 91011121 unsigned int
[4] 31400000 unsigned int
... 0
[15] 0 unsigned int
which is exactly what I want to get; unfortunately, I don't find a way to get either both parts of my number as bmp::int128_t
--for instance--, or the underlying data of my number.
That is, I like something like this exists:
bmp::int128_t integerPart;
bmp::int128_t floatPart;
n.getParts(integerPart, floatPart);
or
auto&& data = n.data(); // which is actually private when using `cpp_dec_float`.
Anyway, does someone known how to do what I am trying to achieve?
For the record, I need this to express a big decimal number as a C# decimal for the sake of interoperability.
From the boost documentation the back end is intentionally opaque as it may change at any time without warning. (Class template cpp_dec_float fulfils all of the requirements for a Backend type. Its members and non-member functions are deliberately not documented: these are considered implementation details that are subject to change.
) from http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/boost_multiprecision/ref/cpp_dec_ref.html
As far as I can see you have two choices here. You can look at the source code for the specific version of the backend class you're using, access it from your number
using the backend
method, and hope that the backend never changes (especially consider changes that only broke binary format and not compilation).
Alternately I would recommend you take the string representation of the cpp_dec_float
and split it into the two parts yourself, using the string
or char*
constructors for the underlying integral types you're interested in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With