Questions tagged [boost-multiprecision]

Boost library for numeric types with arbitrary precision.

The Boost Multiprecision library is a C++ template library that allows the use of numeric types with a greater precision than built-in types. It has templates for integer and floating-point types, and can work with other libraries like and .

Documentation is available on the Boost website.

90 questions
1
vote
2 answers

How to catch boost::wrapexcept from cpp_int?

For some reason there was a change of behavior between boost 1.78 and 1.79 causing now cpp_int convert_to conversion throwing exceptions for very big numbers. Sometimes it is overflow_error, sometimes domain_error. I have not found if it is…
MartinD
  • 11
  • 2
1
vote
1 answer

How to convert huge numbers of boost multiprecision (cpp_bin_float) efficiently?

I have an "extented double" data-type that stores the exponent in a seperate int variable to increase the range like this: struct extDouble { double Value; int Exponent; } I now need to convert a boost multiprecision float (cpp_bin_float)…
Paul Aner
  • 361
  • 1
  • 8
1
vote
0 answers

How to transform a python (long) integer to a boost multiprecision int with C API

I want to transform a python integer to a boost multi precision cpp_int in C++, to be able to work with integers of arbitrary size. My code is entirely in C++, so I need to do this using Python API for C, working with PyObject. I am currently doing…
Vlad Keel
  • 372
  • 2
  • 13
1
vote
1 answer

boost::multiprecision:int128_t(-1) not equal to int128_t ("0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") but their difference is zero

I'm testing boost::multiprecision:int128_t using VS 2022. The value int128_t (-1) is not equal to int128_t ("0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"), but their difference is zero as expected. The issue is illustrated by void TestEqualityof_int128_t…
Catriel
  • 461
  • 3
  • 11
1
vote
2 answers

Precision rounding problem with boost multiprecision

I want to multiply number 123456789.123456789 by 1000000000.0 and as a result of this operation I expect 123456789123456789 as int or float 123456789123456789.0, but I got: res: 123456789123456791.04328155517578125 int_res:…
bladzio
  • 414
  • 3
  • 15
1
vote
2 answers

Boost.Multiprecision cpp_dec_float_50 - convert into an array of bytes and back?

Similar question: to Boost.Multiprecision cpp_int - convert into an array of bytes? But this time related to floating point values. export_bits - doesn't seem to have an overload accepting floating point values limbs of cpp_dec_float_50 are not…
Vega4
  • 969
  • 1
  • 11
  • 25
1
vote
2 answers

QVM - user-defined quaternion and scalar

I am trying use boost::qvm with boost::multiprecision. I built a user-defined quaternion, but I am not able to scale the quaternion. I would like to scale it by a number of type boost::multiprecision::cpp_dec_float_100. Bellow is my code. I also…
orfvl
  • 111
  • 5
1
vote
1 answer

Convert two's complement hex number to boost::multiprecision::int256_t

I'm trying to get boost::multiprecision to parse a negative (two's complement) hex number: #include #include int main(int argc, char* argv[]) { std::string hex_str =…
Thomas Johnson
  • 10,776
  • 18
  • 60
  • 98
1
vote
1 answer

Is it possible to force truncation when instantiating Boost cpp_dec_float from a floating point value?

We are writing software doing arithmetic operations on number with 8 fixed decimal digits (8 decimal digits after the .). We have been bitten by the limited precision of built-in floating point types such a double a few times, mainly on equality…
Ad N
  • 7,930
  • 6
  • 36
  • 80
1
vote
0 answers

boost::multiprecision::cpp_dec_float - Expresison template surprising behavior when using "auto const"?

I've spent the better part of the day tracking a problem down to this example: #include #include int main () { typedef…
namezero
  • 2,203
  • 3
  • 24
  • 37
1
vote
1 answer

boost::multiprecision::cpp_int is being copied then deleted every time I try and print it

When I print a cpp_int from Boost, it seems that the entire object is copied. #include #include using std::cout; void* operator new(size_t size) { void *memory = malloc(size); cout << "New: " <<…
Doot
  • 555
  • 5
  • 15
1
vote
1 answer

Seeding independent bits engine with boosts multiprecision

I have a simple rejection sampling application which is wrapped in a class and used externally as the dummy example below shows. I was able to adapt this post to a boost::multiprecision use case. However I'm not sure how to appropriately seed the…
algae
  • 407
  • 4
  • 15
1
vote
1 answer

How to display C++ Boost Library multi-precision big integers in binary form?

I'm new to Boost and trying to use its multi-precision library to multiply very large inputs: mp::uint1024_t my_1024_bit_int1 = 0b00100101101000100010010...010101; mp::uint1024_t my_1024_bit_int2 = 0b0010101001000101000010100000001001...01010111; //…
Spiegs
  • 11
  • 1
1
vote
1 answer

How to convert boost multiprecision integers into big endian from little endian?

I am trying to fix this part of an abandonware program because I failed to find an alternative program. As you can see the data of PUSH instructions are in the wrong order whereas Ethereum is a big endian machine (address are correctly represented…
user2284570
  • 2,891
  • 3
  • 26
  • 74
1
vote
0 answers

cpp_int (boost) runtime error: Unexpected content found while parsing character string

I'm getting the following runtime error with boost::multiprecision::cpp_int: terminate called after throwing an instance of 'boost::wrapexcept' what(): Unexpected content found while parsing character string. The function…
Jed
  • 11
  • 2