Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack (1) Thread Tools Display Modes
Old 19-03-2008, 01:26 AM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Who stole my Alpaca!
 
FilledVoid's Avatar
 
Join Date: Jan 2005
Location: Kerala
Posts: 2,020
Default Need help with using GMP BigNum Library


Hi all,
I have been working on Project Euler questions and I'm trying to understand how to use this GMP Bignum library and I've read through a bit of the documentation but this is way way more complex than what I expected lol. I'd appreciate if soeone could either post a few SIMPLE examples using it. If you could attach the code, that woulds be great. Please dont post the ones in the demo folder of the gmp library cause I can barely understand them at all lol.
Thanks
__________________
The Ultimate Chess Strategy : "Hit Hard, Hit Fast and Hit Often"
FilledVoid is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 19-03-2008, 05:41 PM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Need help with using GMP BigNum Library

Here's a simple code which adds and subtracts 2 integers among 3:

Code:
#include <gmp.h>

int main(void)
{
    // We declare a few BigNum Integer
    mpz_t I, K, M;
    
    // Some BigNum Floats (Not gonna use them)
    // Just demo
    mpf_t U,J,N;
    
    int n;
    
    // Initialize the Integer I as 0
    // set a value for the rest two (K and M)
    
    // We need to initialize ANY BigNum value
    // Its a must
    
    mpz_init(I); // Initialized with 0
    
    mpz_init(K);
    
    mpz_set_si(K, -3000000);
    // si means Signed Integer
    // set_* is used to set values
    
    mpz_init_set_ui(M, 999999999);
    // Initialized and set via Unsigned at a time
    
    // Similarly one can convert via Double, Strings, etc
    // and even set via other mpz_t values
    // Also use xxx_clear() to clear
    
    // Add M, K and store in I
    mpz_add(I,M,K);
    
    // Subtraction, another example
    mpz_sub(M,K,I);
    
    gmp_printf("I = %Zd, K = %Zd, M = %Zd \n", I, K, M);
    
    // Refer the manual for other _functions_ relating to integers
    
    return 0;
}

/*

Note on GMP in general

There are 3 basic types of Numbers in GMP
    Integer - Represented as "Z"
    Float - Represented as "F"
    Rational - Represented as "Q"

There are some more types, such as Limbs and so,
but I don't know much about them.

So in gmp_printf(), the strings obviously are:
%Z<format> for Integer
%F<format> for Float
%Q<format> for Rational

Where <format> can be any C-allowed printf() type such as:
d - Integer
f - Float
x - Hex

gmp_scanf()'s the same

P.s. Heard that stuff for O/P and I/P are easier in C++ but,
I prefer C
*/
See it in some editor which highlights comments out at least.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 19-03-2008, 05:49 PM   #3 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Need help with using GMP BigNum Library

Are you sure you checked the manual? It seemed pretty simple to me. Just read the part on initialization, then all the arithmetic functions, then the I/O. That should be all you need.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 19-03-2008, 05:52 PM   #4 (permalink)
GTK+ programmer
 
ChaiTan3's Avatar
 
Join Date: Jun 2007
Posts: 121
Default Re: Need help with using GMP BigNum Library

Even I had decided to use BigNum library for some of ProjectEuler's problems. But due to its complexity, learning python turned out to be a simpler option(learning loops and functions hardly takes 10 min)
ChaiTan3 is offline  
Old 19-03-2008, 07:14 PM   #5 (permalink)
Who stole my Alpaca!
 
FilledVoid's Avatar
 
Join Date: Jan 2005
Location: Kerala
Posts: 2,020
Default Re: Need help with using GMP BigNum Library

QwertM : Thank you for the guidance That explains alot.

Quote:
Are you sure you checked the manual? It seemed pretty simple to me. Just read the part on initialization, then all the arithmetic functions, then the I/O. That should be all you need.
Hmm Maybe Im looking at the wrng manual then. But I felt that it was way too complex .

Quote:
Even I had decided to use BigNum library for some of ProjectEuler's problems. But due to its complexity, learning python turned out to be a simpler option(learning loops and functions hardly takes 10 min)
yeah I've beent empted to change to Python but I'd like to make sure I atleast try in C befoer I give up.
__________________
The Ultimate Chess Strategy : "Hit Hard, Hit Fast and Hit Often"
FilledVoid is offline  
Old 20-03-2008, 05:55 AM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Need help with using GMP BigNum Library

This is the right manual:

http://gmplib.org/manual/index.html
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 20-03-2008, 01:20 PM   #7 (permalink)
Who stole my Alpaca!
 
FilledVoid's Avatar
 
Join Date: Jan 2005
Location: Kerala
Posts: 2,020
Default Re: Need help with using GMP BigNum Library

Quote:
This is the right manual:

http://gmplib.org/manual/index.html
Thank you
__________________
The Ultimate Chess Strategy : "Hit Hard, Hit Fast and Hit Often"
FilledVoid is offline  
Old 20-03-2008, 06:38 PM   #8 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Need help with using GMP BigNum Library

The entire python standard library _is_ written in C. So if you maximize your usage of builtins, you'll be able to get C's speed, and write in python, which is heavenly.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/programming/82996-need-help-using-gmp-bignum-library.html
Posted By For Type Date
with using GMP BigNum Library Programming Question This thread Refback 21-07-2010 08:44 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Suggest a CD/DVD Library SW hailgautam Software Q&A 5 03-09-2007 11:36 PM
Software Library. Anindya Software Q&A 3 29-04-2007 12:32 PM
PS Font Library nitnew Software Q&A 2 06-02-2007 07:56 PM
CD Library q3_abhi QnA (read only) 6 20-08-2005 09:00 AM
msdn library iinfi QnA (read only) 2 12-04-2005 12:07 AM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:55 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2