multiprecision

how to change at runtime number precision with boost::multiprecision

折月煮酒 提交于 2019-12-01 19:45:56
I've read from the boost::multiprecision documentation : Depending upon the number type, precision may be arbitrarily large (limited only by available memory), fixed at compile time (for example 50 or 100 decimal digits), or a variable controlled at run-time by member functions. The types are expression-template-enabled for better performance than naive user-defined types. I've read some more documentation but I've not found anything regarding changing precision at runtime. I've seen only templates that allows me to set precision at compile time, that's not what I want (I want to create a

How to use sqrt and ceil with Boost::multiprecision?

北城以北 提交于 2019-12-01 19:35:42
Do you know how to do this simple line of code without error using Boost::multiprecison ? boost::multiprecision::cpp_int v, uMax, candidate; //... v += 6 * ceil((sqrt(uMax * uMax - candidate) - v) / 6); Using MSVC there is an error for "sqrt" and it's possible to fix it with: v += 6 * ceil((sqrt(static_cast<boost::multiprecision::cpp_int>(uMax * uMax - candidate)) - v) / 6); Then there is an error for "ceil" and it's possible to fix it with: namespace bmp = boost::multiprecision; typedef bmp::number<bmp::cpp_dec_float<0>> float_bmp; v += 6 * ceil(static_cast<float_bmp>((sqrt(static_cast<bmp:

Is it possible to store 2 32-bit values in one long int variable?

白昼怎懂夜的黑 提交于 2019-12-01 19:08:52
问题 I want to store two 32-bit values in a single long int variable. How would you do this on a 32-bit OS using C? Is it possible to store the data in a single long long variable? If so, how is that done? 回答1: Assuming a long is 64 bits on your platform, int v1 = 123; int v2 = 456; long val = v1 << 32 | v2; 回答2: Use an uint64_t and bitwise operators. uint64_t i64; uint32_t a32, b32; // Be carefull when shifting the a32. // It must be converted to a 64 bit value or you will loose the bits //

how to change at runtime number precision with boost::multiprecision

蓝咒 提交于 2019-12-01 04:23:09
问题 I've read from the boost::multiprecision documentation: Depending upon the number type, precision may be arbitrarily large (limited only by available memory), fixed at compile time (for example 50 or 100 decimal digits), or a variable controlled at run-time by member functions. The types are expression-template-enabled for better performance than naive user-defined types. I've read some more documentation but I've not found anything regarding changing precision at runtime. I've seen only

Storing and printing integer values greater than 2^64

谁都会走 提交于 2019-11-27 23:59:09
I am trying to write a program for finding mersenne prime numbers. Using the unsigned long long type I was able to determine the value of the 9th mersenne prime, which is (2^61)-1. For larger values I would need a data type that could store integer values greater than 2^64. Please help. (I should be able to use operators like , =,>,< and % with this data type.) You can not do what you want with C natives types, however there are libraries that let handle arbitrarily large numbers, like the GNU Multiple Precision Arithmetic Library . To store large numbers, there are many choices, which are

Storing and printing integer values greater than 2^64

随声附和 提交于 2019-11-27 04:42:09
问题 I am trying to write a program for finding mersenne prime numbers. Using the unsigned long long type I was able to determine the value of the 9th mersenne prime, which is (2^61)-1. For larger values I would need a data type that could store integer values greater than 2^64. Please help. (I should be able to use operators like , =,>,< and % with this data type.) 回答1: You can not do what you want with C natives types, however there are libraries that let handle arbitrarily large numbers, like