<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
Hi Rafael,<BR>
This works to get the digits from an mpz_t variable. I did it with a char array<BR>but you could use pointers if you like.<BR>
<BR>
#include <stdio.h><BR>#include <math.h><BR>#include <windows.h><BR>#include <string.h><BR>#include <stdlib.h><BR>#include "gmp.h"<BR>#define getz(a) mpz_inp_str(a,stdin,10)<BR><BR>
int main(int argc, char * argv[])<BR>{<BR>int i;<BR>char digit[2000];<BR>char *tmp;<BR> mpz_t num;<BR>printf(" Get mpz digits \n");<BR>while(1)<BR>{<BR> mpz_init(num);<BR>printf("num\n");<BR>getz(num);<BR>mpz_get_str (digit,10,num);<BR>for(i=0;i<strlen(digit);i++)<BR>printf("%c",(int)digit[i]);<BR>printf("\n");<BR>}<BR> return 0;<BR>}<BR>
<BR>
Input/Output:<BR>
Get mpz digits<BR>num<BR>3141592653589793238462643383<BR>3141592653589793238462643383<BR>num<BR>
<BR>
Cino Hilliard<BR>
<BR>> Today's Topics:<BR>> <BR>> 1. Re: Addressing single digits of big integers (decio@decpp.net)<BR>> <BR>> <BR>> ----------------------------------------------------------------------<BR>> <BR>> Message: 1<BR>> Date: Fri, 25 Jul 2008 19:29:08 -0300<BR>> From: "decio@decpp.net" <decio@decpp.net><BR>> Subject: Re: Addressing single digits of big integers<BR>> To: "Rafael Anschau" <rafael.anschau@gmail.com>, gmp-discuss@swox.com<BR>> Message-ID: <488a53b4.94.2466.821384423@seti.serverlogistics.com><BR>> Content-Type: text/plain; charset="iso-8859-1"<BR>> <BR>> <BR>> ----- Original Message -----<BR>> From: "Rafael Anschau" <rafael.anschau@gmail.com><BR>> To: gmp-discuss@swox.com<BR>> Subject: Addressing single digits of big integers<BR>> Date: Thu, 24 Jul 2008 16:48:03 -0300<BR>> <BR>> > Is it possible to address single digits in big integers,<BR>> > without the high costs of export import ? Something like a<BR>> > pointer to the digit ?<BR>> <BR>> If by digit you mean a base-10 digit, sorry, it's gonna be<BR>> fairly costly. Most large integer packages represent values<BR>> internally in a power-of-two base, so you can't directly get<BR>> base-10 digits, only base-2^k digits. To get base-10 digits<BR>> you'll have to incur the cost of changing representation by<BR>> exporting, or doing a calculation like x/10^k mod 10, and<BR>> both the division and the modulo are costly for large<BR>> values.<BR>> <BR>> If you routinely need to work with the base-10<BR>> representation of your large integers, and it's a bottleneck<BR>> of your code (profile it somewhere to be sure, otherwise you<BR>> may lose performance by following this advice), try a<BR>> different library which works with a power-of-10 base<BR>> representation. I can't name any, but I know that most of<BR>> the various Pi-calculator programs out there use base-10<BR>> extensively to avoid a costly change of representation at<BR>> the end.<BR>> <BR>> D?cio<BR>> <BR>> <BR>> ------------------------------<BR>> <BR>> _______________________________________________<BR>> gmp-discuss mailing list<BR>> gmp-discuss@swox.com<BR>> https://gmplib.org/mailman/listinfo/gmp-discuss<BR>> <BR>> <BR>> End of gmp-discuss Digest, Vol 59, Issue 9<BR>> ******************************************<BR><BR></body>
</html>