Thread: GMP Library: simple question

  1. #1
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31

    Exclamation GMP Library: simple question

    Hi.

    I've written a small program to compute very large numbers using the Collatz Conjecture. I have been told I should use the GMP library, so I downloaded the file, and there's a bunch of .c and .h files. So what I did was paste inside the folder my own .c file and use the headers gmp.h

    However I am still unable to make use of large numbers such as 1000000000000000.

    How can I fix this?
    And if I successfully use the GMP library to work with large numbers, will they be absolutely precise?

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    #include "gmp.h"
    int main(void){
    	unsigned long i,cont,iter;
    	cont=0;
    	for(i=1000000000000000;i<=1000000000000010;i++){
    		iter=i;
    		do{
    			if(iter%2==0){
    				iter/=2;
    				cont++;}
    			else{
    				iter=iter*3+1;
    				cont++;}
    		}while(iter!=1);
    		printf("Collatz Conjecture - iteration: %d\t\t\tsteps:%d\t\t\t\n",i,cont);
    		cont=0;}
    	return 0;
    }
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Have you done something crazy like read the manual? Using GSL doesn't extend long to be magically large.

    EDIT: And also, you have to build the library (since you downloaded the source, instead of downloading the library binaries).

  3. #3
    Registered User KAUFMANN's Avatar
    Join Date
    Jan 2011
    Location
    Coimbra, Portugal
    Posts
    31
    Quote Originally Posted by tabstop View Post
    Have you done something crazy like read the manual? Using GSL doesn't extend long to be magically large.

    EDIT: And also, you have to build the library (since you downloaded the source, instead of downloading the library binaries).
    Oh there's a Manual alright. Thank you very much. That shall suffice.
    ˙uıɐƃɐ ʎɐq-ǝ ɯoɹɟ pɹoqʎǝʞ ɹǝɥʇouɐ ƃuıʎnq ʇou ɯı

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. little help in simple socket library
    By SIFE in forum Networking/Device Communication
    Replies: 1
    Last Post: 12-31-2010, 11:01 PM
  2. Simple Socket Library Not so simple
    By jbully in forum C Programming
    Replies: 4
    Last Post: 12-23-2010, 09:23 AM
  3. need simple file encryption library
    By akaash19 in forum C Programming
    Replies: 6
    Last Post: 02-12-2010, 11:38 AM
  4. Need simple C graphics library
    By Sharke in forum C Programming
    Replies: 4
    Last Post: 02-16-2009, 10:25 PM
  5. Linker errors with simple static library
    By Dang in forum Windows Programming
    Replies: 5
    Last Post: 09-08-2001, 09:38 AM