Note that there are some explanatory texts on larger screens.

plurals
  1. POGMP Overflow when using large numbers
    primarykey
    data
    text
    <p>I'm working on a program to factor very large numbers (20 digits or more) in C++ and am using GMP to deal with overflow issues. My program is working well for numbers of about 10 digits or less, but when I throw a 15 digit number at it, it blows up. I'm going to boil my program down to simply one line like this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;gmp.h&gt; #include &lt;gmpxx.h&gt; using namespace std; int main() { mpz_class n = 48112959837082048697; //this blows up return 0; } </code></pre> <p>If I replace that line with </p> <pre><code>mpz_class n = 12623773; </code></pre> <p>then everything works just fine.</p> <p>Here is the error:</p> <pre><code>$ g++ -o main main.cpp -lgmpxx -lgmp main.cpp: In function ‘int main()’: main.cpp:21:19: error: conversion from ‘long long int’ to ‘mpz_class’ is ambiguous /usr/include/gmpxx.h:1563:3: note: candidates are: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(double) /usr/include/gmpxx.h:1562:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(float) /usr/include/gmpxx.h:1560:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(long unsigned int) /usr/include/gmpxx.h:1559:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(long int) /usr/include/gmpxx.h:1557:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(short unsigned int) /usr/include/gmpxx.h:1556:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(short int) /usr/include/gmpxx.h:1554:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(unsigned int) /usr/include/gmpxx.h:1553:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(int) /usr/include/gmpxx.h:1551:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(unsigned char) /usr/include/gmpxx.h:1550:3: note: __gmp_expr&lt;__mpz_struct [1], __mpz_struct [1]&gt;::__gmp_expr(signed char) </code></pre> <p>Anybody know how to fix this so that I can use large numbers? I thought that GMP was supposed to allow something like 500 digits, plus or minus.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload