multiprecision

Using Boost.Random to generate multiprecision integers from a seed

六眼飞鱼酱① 提交于 2019-12-11 11:11:55
问题 I am attempting to use the Boost multiprecision libraries for C++ to generate large random numbers. I have been unable to create a generator which is seeded by the time or another random number, so my generator produces the same numbers on every run. How do I seed the generator with a changing value to produce different values on each run? Here is the code which works but produces the same values on each run: using namespace boost::multiprecision; using namespace boost::random; typedef

Print cpp_dec_float in scientific notation without trailing zeros

故事扮演 提交于 2019-12-10 21:18:17
问题 I'm using cpp_dec_float for arbitrary precision, and it's great, but I'm having trouble figuring out how to print all significant digits. For example, with this code to setup using boost::multiprecision::cpp_dec_float; typedef boost::multiprecision::number<cpp_dec_float<100>> mp_type; mp_type test_num("7.0710678118654752440084436210484903928483593768847403658833986900e-01"); and if I simply print with std::cout << std::scientific << test_num << std::endl; the result is 7.071068e-01 , so that

Writing HugeInteger class

牧云@^-^@ 提交于 2019-12-08 11:17:08
问题 I am new to C++ and this is what I am suppose to do for an assignment. Create a class HugeInteger that uses a 40-element array of digits to store integers as large as 40 digits each. Provide member functions input, output, add and subtract. For comparing HugeInteger objects, provide functions isEqualTo, isNotEqualTo, isGreaterThan, isLessThan, isCreaterThanOrEqualTo and isLessThanOrEqualTo - each of these is a "predicate" function that simply returns true if the relationship holds between the

How to convert from boost::multiprecision::cpp_int to cpp_dec_float<0> (rather than to cpp_dec_float_50, etc.)?

≯℡__Kan透↙ 提交于 2019-12-07 09:48:41
问题 As is made clear in the Boost Multiprecision library documentation, it is straightforward to convert from a boost::multiprecision::cpp_int to a boost::multiprecision::cpp_dec_float : // Some interconversions between number types are completely generic, // and are always available, albeit the conversions are always explicit: cpp_int cppi(2); cpp_dec_float_50 df(cppi); // OK, int to float // <-- But fails with cpp_dec_float<0>! The ability to convert from a cpp_int to a fixed-width floating

Force cpp_dec_float to round down

这一生的挚爱 提交于 2019-12-06 09:02:08
问题 I am using .str(n, std::ios_base::scientific) to print ccp_dec_float s. I've noticed that it rounds up. I am using cpp_dec_float for accounting, so I need to round downward. How can this be done? 回答1: It doesn't round up. In fact, it does banker's round: See it Live On Coliru #include <boost/multiprecision/number.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <iostream> namespace mp = boost::multiprecision; int main() { using Dec =

Force cpp_dec_float to round down

£可爱£侵袭症+ 提交于 2019-12-04 11:46:46
I am using .str(n, std::ios_base::scientific) to print ccp_dec_float s. I've noticed that it rounds up. I am using cpp_dec_float for accounting, so I need to round downward. How can this be done? It doesn't round up. In fact, it does banker's round: See it Live On Coliru #include <boost/multiprecision/number.hpp> #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <iostream> namespace mp = boost::multiprecision; int main() { using Dec = mp::cpp_dec_float_50; for (Dec d : { Dec( "3.34"), Dec( "3.35"), Dec( "3.38"), Dec( "2.24"), Dec( "2.25"),

creating math constants of variable precision using Boost mpfr_float, such as pi or e

♀尐吖头ヾ 提交于 2019-12-02 15:53:56
问题 I am using Boost.Multiprecision for wrappers around the mpfr backend, and I am having some trouble creating pi (and e or any other math constant) to my desired precision. I feel like what I want to do should be possible, because of the use of Boost.Math for constants on a tutorial page for Boost.Multiprecision. In the tutorial, they use fixed-precision numbers of types such as cpp_dec_float_50 -- I want to do it with variable_precision mpfr_float . Check out the following code: #include

creating math constants of variable precision using Boost mpfr_float, such as pi or e

蓝咒 提交于 2019-12-02 08:59:58
I am using Boost.Multiprecision for wrappers around the mpfr backend, and I am having some trouble creating pi (and e or any other math constant) to my desired precision. I feel like what I want to do should be possible, because of the use of Boost.Math for constants on a tutorial page for Boost.Multiprecision . In the tutorial, they use fixed-precision numbers of types such as cpp_dec_float_50 -- I want to do it with variable_precision mpfr_float . Check out the following code: #include <boost/multiprecision/mpfr.hpp> #include <boost/math/constants/constants.hpp> #include <iostream> ... int

boost serialization of mpfr_float

孤街浪徒 提交于 2019-12-02 04:21:54
问题 I would like to serialize a custom class containing an boost::multiprecision::mpfr_float as a member. It says here in the Boost.Serialization documentation that a type T is serializable iff at least one of 5 properties is true, and here at the Multiprecision documentation that the number class has pass-through support which requires the underlying backend to be serializable. For Boost.Multiprecision's mpfr_float type, I know: It is not a primitive type. It is a class type, but it doesn't have

boost serialization of mpfr_float

♀尐吖头ヾ 提交于 2019-12-01 23:24:41
I would like to serialize a custom class containing an boost::multiprecision::mpfr_float as a member. It says here in the Boost.Serialization documentation that a type T is serializable iff at least one of 5 properties is true, and here at the Multiprecision documentation that the number class has pass-through support which requires the underlying backend to be serializable. For Boost.Multiprecision's mpfr_float type, I know: It is not a primitive type. It is a class type, but it doesn't have the serialize function(s) defined. It is not a pointer to a Serializable type. It is not a reference