标签: gmp

如何正确进行 GMP 位移?

我需要使用高精度整数进行一些计算,并希望使用 GMP 库。我希望这里有人有经验,因为我不明白如何使用位移位。我正在尝试使用下面的代码。代码可以编译,但 b 仍然包含 0。

https://gmplib.org/manual/Low_002dlevel-Functions

#include <stdio.h>                                                                                                                                                                                                                           
#include <gmp.h>                                                                                                                                                                                                                             
                                                                                                                                                                                                                                             
int main()                                                                                                                                                                                                                                   
{                                                                                                                                                                                                                                            
                                                                                                                                                                                                                                             
    mpz_t a;                                                                                                                                                                                                                                 
    mpz_t b;                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                             
    mpz_init2(b, a->_mp_size);                                                                                                                                                                                                               
    mpz_set_str(a, "1", 16);                                                                                                                                                                                                                 
                                                                                                                                                                                                                                             
    mp_limb_t bits = mpn_lshift(b->_mp_d, &a->_mp_d[0], a->_mp_size, 1);                                                                                                                                                                     
                                                                                                                                                                                                                                             
    gmp_printf("%Zx\n", a);                                                                                                                                                                                                                  
    gmp_printf("Bits shifted %M\n", bits);                                                                                                                                                                                                   
    gmp_printf("%Zd", b);                                                                                                                                                                                                                    
                                                                                                                                                                                                                                             
    return 0;                                                                                                                                                                                                                                
}      
Run Code Online (Sandbox Code Playgroud)

c gmp

1
推荐指数
1
解决办法
1531
查看次数

GMP和智能指针

我正在使用gnump并且有一个必须返回的函数mpz_t.所以我必须使用原始指针来返回一个值.我new为指针分配空间并将其作为参数发送到我的函数中.

我认为使用智能指针会更好.但我之前没有和他们合作过.我阅读了手册,但仍然无法理解如何shared_ptr正确使用从函数返回变量.

shared_ptr<mpz_t> func()
{
    mpz_t z;
    mpz_init_set_str(z, "23423423423", 10);

    shared_ptr<mpz_t> p /* Shall I allocate space with "new" or smth else?.. */

    return p;
}
Run Code Online (Sandbox Code Playgroud)

我会感激任何一个例子.

c++ boost gmp

0
推荐指数
1
解决办法
705
查看次数

gmpy源代码

有什么办法可以看一下源代码gympy吗?具体来说,gmpy2.is_prime.

我试过各种链接

我找不到任何地方.

我已经下载了gmpy2,并在我的本地驱动器上进行了检查,但文件扩展名为.pyd.当我打开它(在记事本中)时,以下是我看到的前几行 -

MZ       ÿÿ  ¸       @                                   ð   º ´  Í!¸LÍ!This program     cannot be run in DOS mode.
Run Code Online (Sandbox Code Playgroud)

剩下的就是胡言乱语.

我想写一个非常快速的素数检查器,它是迄今为止遇到的最好的任何人都可以告诉我如何获得源代码?或者也许链接到其他一些快速检查者的源代码(或讨论)?

python primes gmp

0
推荐指数
1
解决办法
699
查看次数

在Red Hat Enterprise linux 6.5上安装GCC 4.8.2

我是Red Hat Enterprise linux的新手.我在Red Hat Enterprise Linux 6.5上编译gcc 4.8.2时面临问题;我从GNU webite中获取源代码.我按照这个链接中的步骤 http://gcc.gnu.org/wiki/InstallingGCC 发出的命令是:

tar xzf gcc-4.6.2.tar.gz
cd gcc-4.6.2
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.8.2/configure 

checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libitm …
Run Code Online (Sandbox Code Playgroud)

linux gcc mpfr gmp mpc

0
推荐指数
1
解决办法
3万
查看次数

使用GNU MP"大数字"库的"Aborted"程序

我正在尝试使用大数字在C中实现以下(伪代码-python):

while i * i < n:
    if n % i:
    i += 1
Run Code Online (Sandbox Code Playgroud)

我想出了以下使用gmp.h库:

#include <stdio.h>
#include <gmp.h>

int main () {
    mpz_t n;
    mpz_t i;
    mpz_t o; // Hold constant mpz "1" for incrementing i
    mpz_t x; // Holds "i * i" each loop

    mpz_set_str(n, "338852330881981183", 10);
    mpz_set_str(i, "2", 10);
    mpz_set_str(o, "1", 10);
    mpz_set_str(x, "4", 10);


    while( mpz_cmp(x, n) < 0 ) {
        mpz_add(i, i, o);
        mpz_pow_ui(x, i, 2);
    }

    mpz_clear(i);
    mpz_clear(n);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我使用GCC编译时,我没有收到任何错误,但是当我尝试运行程序时,我得到以下内容 …

c gmp

0
推荐指数
1
解决办法
235
查看次数

C++ GMP生成随机数

我正在尝试使用GMP库在C++中生成一个巨大的随机数,但是在查明语法时遇到了问题.这与我发现的其他例子略有不同,因为我需要为随机数设置一个楼层和天花板.这是我需要做的事情:

mpz_class high, low;

low  = pow(2,199);
high = pow(2,210);

// code to use the high and low numbers to generate the random number
Run Code Online (Sandbox Code Playgroud)

我知道这不是很多,但是,我不知道在这一点上语法甚至是什么,我已经尝试了几件事,但我发现没有什么能让我告诉GMP使用高和数字生成的低范围.

思考?

c++ random biginteger gmp

0
推荐指数
2
解决办法
2842
查看次数

无法在centOS中安装GMP

我正在尝试在我的centOS服务器上安装GMP库(https://gmplib.org/),但是没有运气。

我运行此命令:-

./configure
Run Code Online (Sandbox Code Playgroud)

它给了我这个结果:-

[root@centos-512mb-ams3-01 gmp-4.2.2]# ./configure
checking build system type... pentium3-unknown-linux-gnu
checking host system type... pentium3-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=32
checking compiler gcc -m32 -O2 -fomit-frame-pointer ... no
checking compiler gcc -O2 -fomit-frame-pointer ... yes
checking compiler gcc -O2 -fomit-frame-pointer has sizeof(long)==4... no
checking compiler icc …
Run Code Online (Sandbox Code Playgroud)

php centos gmp

0
推荐指数
1
解决办法
3792
查看次数

使用OpenMP循环时的线程安全

我正在使用C ++和GMP开发小型Collat​​z猜想计算器,并且正在尝试使用OpenMP在其上实现并行性,但是遇到了有关线程安全性的问题。就目前而言,尝试运行代码将产生以下结果:

*** Error in `./collatz': double free or corruption (fasttop): 0x0000000001140c40 ***
*** Error in `./collatz': double free or corruption (fasttop): 0x00007f4d200008c0 ***
[1]    28163 abort (core dumped)  ./collatz
Run Code Online (Sandbox Code Playgroud)

这是重现该行为的代码。

 #include <iostream>
 #include <gmpxx.h>

 mpz_class collatz(mpz_class n) {
     if (mpz_odd_p(n.get_mpz_t())) {
         n *= 3;
         n += 1;
     } else {
         n /= 2;
     }
     return n;
 }

 int main() {
     mpz_class x = 1;
 #pragma  omp parallel
     while (true) {
         //std::cout << x.get_str(10);
         while (true) {
             if …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading openmp gmp

0
推荐指数
1
解决办法
704
查看次数

通过Homebrew在macOS High SIerra上安装GMP

我一直试图在我的机器上运行:https://github.com/Minishlink/web-push-php-example

创建项目并更改到composer install返回的目录后:

Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Run Code Online (Sandbox Code Playgroud)

它列出的问题看起来都接近这个:

the requested PHP extension gmp is missing from your system.
Run Code Online (Sandbox Code Playgroud)

所以我通过Homebrew安装了gmp.

之后搜索gmp返回了这个:

==> Searching local taps...
gmp ?
==> Searching taps on GitHub...
==> Searching blacklisted, migrated and deleted formulae...
Run Code Online (Sandbox Code Playgroud)

但是,如果我检查列表,它返回的php -m是不存在的.

我也尝试将扩展名添加extension=gmp.so到php.ini,这导致了新的错误.

PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20160303/php_gmp.so'
Run Code Online (Sandbox Code Playgroud)

当然, …

php gmp composer-php

0
推荐指数
1
解决办法
1983
查看次数

使用GMP整数时出现分段错误(核心转储)

我在C++中编写了一个简单的程序,使用gmp库,它打印出数字模数,其数字由1组成(如1,11,111,1111,1111,...)和2001; 问题是当程序达到23位数1时,我得到一个错误说Segmantation fault(core dumped).你能指出问题出在哪里吗?这是我的代码:

#include <iostream>
#include <stdio.h>
#include <string>
#include <gmpxx.h>

int main(int argc, char** args){

    mpz_t currNumber;
    mpz_init(currNumber);   
    mpz_set_str(currNumber, "1", 10);

    while(mpz_sizeinbase(currNumber, 10) < 24){
        char* digits =  mpz_get_str(nullptr, 10, currNumber);
        strcat(digits, "1");
        mpz_set_str(currNumber, digits, 10);
        digits = nullptr;


        mpz_t r;
        mpz_init(r);    
        mpz_set_str(r, "1", 20);

        mpz_t divisor;
        mpz_init(divisor);  
        mpz_set_str(divisor, "2001", 20);


        mpz_mmod(r, currNumber, divisor);

        std::cout << "====>" << currNumber << " mod(2001) = " << r << "\n\n\n";

        //Clean up
        mpz_clear(r);
        mpz_clear(divisor);     
    }

    std::cout << "Went until " …
Run Code Online (Sandbox Code Playgroud)

c++ gmp

-2
推荐指数
1
解决办法
547
查看次数

如何用整数初始化 GMP mpz_t

我想mpz_t用一个整数(例如 2)从 GMP 初始化 a 。我尝试过以下变体:

mpz_t n(2); // Compiler error
mpz_t n = 2; // Compiler error
Run Code Online (Sandbox Code Playgroud)

初始化到2的正确方法是什么mpz_t

c++ gmp

-2
推荐指数
1
解决办法
2068
查看次数

在带有新 A1 芯片(苹果芯片)的新 macbook pro 中安装 php@7.3

我正在尝试在我的带有 Apple A1 芯片的新 Macbook Pro 上安装 HD-Wallet Derive。为此,我需要安装最新版本的 PHP(目前为 7.3)所以当我brew install php@7.3在终端(zsh)上点击此命令时,我收到此错误消息:Error: php@7.3: no bottle available!

您可以尝试从源代码安装: brew install --build-from-source php@7.3 请注意不支持从源代码构建。您会遇到一些公式的构建失败。如果您遇到任何问题,请创建拉取请求,而不是在 Homebrew 的 GitHub、Twitter 或任何其他官方渠道上寻求帮助。

我正在从源头构建它。使用这个回购。https://github.com/dan-da/hd-wallet-derive#installation-and-running 我能执行此命令curl https://getcomposer.org/installer -o installer.php,这php installer.php成功。但是当我运行这个php composer.phar install

我收到此错误:未找到锁定文件。更新依赖项而不是从锁定文件安装。如果您没有锁定文件,请使用 composer update 而非 composer install。

使用包信息加载 Composer 存储库 更新依赖项 您的需求无法解析为一组可安装的包。

问题 1 - mdanter/ecc[v0.5.0, ..., 0.5.x-dev] 需要 ext-gmp * -> 它从您的系统中丢失。安装或启用 PHP 的 gmp 扩展。- bitwasp/bitcoin dev-master 需要 mdanter/ecc ^0.5.0 -> 可满足 mdanter/ecc[v0.5.0, v0.5.1, v0.5.2, …

php macos homebrew gmp

-2
推荐指数
2
解决办法
1732
查看次数

标签 统计

gmp ×12

c++ ×5

php ×3

c ×2

biginteger ×1

boost ×1

centos ×1

composer-php ×1

gcc ×1

homebrew ×1

linux ×1

macos ×1

mpc ×1

mpfr ×1

multithreading ×1

openmp ×1

primes ×1

python ×1

random ×1