gmp

Big primes loop with GMP library C++

冷暖自知 提交于 2021-02-10 15:51:21
问题 It's the first time that I use the gmp library, so I'm really lost, I've found a code implementing the "miller rabin primality test" in c++ but I wanted to be able to apply it to integers with arbitrary precision so I installed the GMP library. The problem is, I've got no idea of how GMP library actually works (I've read trough a few pages of the manual but I understand very little about it also since I haven't even studied object oriented programming), I want to adapt the primality test to

Fixed size integers with gmp…?

天涯浪子 提交于 2021-02-07 08:50:37
问题 I've been trying for days to install GMP library under MINGW. I have been using for weeks __uint128_t with gcc under a linux64 bit environment, then ported the same program under GMP and mingw (32 bit version). I used mpz_class integers instead of __uint128_t . Then I started my new program and...! With __uint128_t and 64 bit it takes 16 minutes to complete, with GMP and MINGW it takes 91 HOURS!!! What should I do to speed up things a bit? Is there any faster way to do 128 bit integer math

Fixed size integers with gmp…?

坚强是说给别人听的谎言 提交于 2021-02-07 08:49:23
问题 I've been trying for days to install GMP library under MINGW. I have been using for weeks __uint128_t with gcc under a linux64 bit environment, then ported the same program under GMP and mingw (32 bit version). I used mpz_class integers instead of __uint128_t . Then I started my new program and...! With __uint128_t and 64 bit it takes 16 minutes to complete, with GMP and MINGW it takes 91 HOURS!!! What should I do to speed up things a bit? Is there any faster way to do 128 bit integer math

Installing GCC from source on Alpine

时光毁灭记忆、已成空白 提交于 2021-02-07 05:28:17
问题 While trying to install GCC 6.4.0 on Alpine, I run into: checking for the correct version of gmp.h... yes checking for the correct version of mpfr.h... yes checking for the correct version of mpc.h... yes checking for the correct version of the gmp/mpfr/mpc libraries... no But in /usr/lib , which seems to be the standard lookup directory, I have: libgmp.a libgmp.so libgmp.so.10 libgmp.so.10.3.2 libmpc.so.3 libmpc.so.3.0.0 libmpfr.so.4 libmpfr.so.4.1.5 What could be wrong? 回答1: The quickest

How to compile GMP for windows using Visual Studio

时间秒杀一切 提交于 2021-02-04 19:49:06
问题 I am trying to install gmp on windows. I have found the mingw way of compiling from sources on windows. But was unable to find binaries fro gmp 6.1.2 or visual studio project in order to compile from sources. So the question is: Where can I download the gmp 6.1.2 binaries or compile from sources using Visual Studio. 回答1: Compiling GMP on Windows with VisualStudio might be tricky, however there are already some SO questions, that might help you (depending on your exact use-case): Building GMP

Convert size_t to integer

*爱你&永不变心* 提交于 2021-01-29 09:18:57
问题 I'm working with moderately sized integers which are of a size so that their logarithm would be an int. I'm using the GNU Multiprecision library (GMP) with the C programming language. I wonder whether there exists a function that would convert the data type size_t into an int. 回答1: Source: src size_t is implementation dependent yeah, and it's size may vary. You can try to typecast it to int but that may not be able to store as you already mentioned indirectly. But still you can work with

Error creating R package: Error in dyn.load(file, DLLpath = DLLpath, …)

夙愿已清 提交于 2021-01-28 08:31:13
问题 I am creating an R package called CVOC. It includes C++ code and uses high precision arithmetic from the C library gmp. The package is to be created by the following steps: 1) using Rcpp::Rcpp.package.skeleton to create the package skeleton. 2) copying the required files, such as DESCRIPTION, NAMESPACE, Makevars, etc. , into the correct folders 3) creating the .Rd documentation files using roxygen2::roxygenise() 4) checking the R-package using R CMD check 5) building the R-package using R CMD

Why is incorrect value of pi output?

点点圈 提交于 2021-01-28 07:50:29
问题 I'm trying to calculate pi using following code that uses Chudnovsky algorithm. When $n is increased, then number of digits after the decimal point. However when $n is small, it can calculate correct value of pi (3.141592...) is output, but when $n is increased, it calculate incorrect value of pi. Why? #!/usr/bin/perl use strict; use warnings; use GMP qw(:all); use GMP::Mpf qw(:all); use GMP::Mpz qw(:all); use GMP::Mpq qw(:all); my $n = shift; $n = $n<7?7:$n; $n *= 8; my $l = int($n/7) + 1;

How can I check if std::pow will overflow double

▼魔方 西西 提交于 2021-01-28 03:22:15
问题 I have a function that deals with arbitrarily large grids. I need to compute if a grid to the power of another number will fit into a double due to using std::pow . If it cannot, I want to take a different branch and use gnu multiprecision library instead of normal. Is there a quick way to see if: int a = 1024; int b = 0-10; if(checkPowFitsDouble(a, b)) { long c = static_cast<long>(std::pow(a, b)); //this will only work if b < 6 } else { mpz_t c; //yada yada gmp } I am completely stumped on

Are there any limits to GMP?

北慕城南 提交于 2021-01-27 19:22:20
问题 All the documentation for GMP seems to imply that there are no limits. Is this really true? I want to do some simple integer maths (add, shift, xor, multiply, divide etc) but with truly enormous numbers up to 2^2^96 (that is 2^79,228,162,514,264,337,593,543,950,336 which is likely to be orders of magnitude more memory than you have in your computer) or even 2^2^256. If I go to the trouble of getting GMP and coding against it would it raise its eyebrows at me for asking for such extraordinary