changing word length

This is a discussion on changing word length within the C++ Programming forums, part of the General Programming Boards category; ok, i am working on a prime number generator/counter (gee, bet ya haven't heard that one today....), i have most ...

  1. #1
    Registered User mltngpot's Avatar
    Join Date
    Jan 2006
    Posts
    5

    changing word length

    ok, i am working on a prime number generator/counter (gee, bet ya haven't heard that one today....), i have most of my code written however, except for some of the math, in as much, i want to find super large primes. in order to do this, i need to either do one of two things, 1) write my own math header file, it would be a pain in the arse, but doable.
    2) change the word size of an int to 32 bit to say 128 bit, or larger.
    now i did find out from delorie.com that i can change some variables in machine.h/.c (gcc 3.4) which would change the word length, but with this supersized numbers, would that still be possible since i am only running a 32 bit processor since 64bit math is emulated?

    my questions:
    So does anyone know how to do so?
    is it possible to change the word size dynamically? i dont want to waste 128 bits to show that 3 is a prime number.

    i am running linux so if need be, i can change the enviroment arround a little, but i would rather not if possible.

    any help is appreciated, any usefull help is much appreciated.
    thanks.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    what difference does it make that you use a 32-bit, 64-bit, 128-bit etc. number to show that 3 is a prime number? If it does make a difference you need to buy more memory in your computer. 128 bits isn't worth worrying about. you have much bigger fish to fry than that.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    Tell me, have you already read the considerable material you can easily obtain by typing in rather simple terms like "compute prime numbers" to your favourite search engine?

    > i can change some variables in machine.h/.c (gcc 3.4) which would change the word length,
    Only makes sense if the underlying processor is of that width.
    If your processor is 32 bit, and you change this to say 128 bit, then I doubt the compiler is going to magically create some code to handle it for you.

    If you're not going to do it yourself, find a bignum package like say "GMP"

  4. #4
    Registered User mltngpot's Avatar
    Join Date
    Jan 2006
    Posts
    5
    well, currently the largest merrsine prime is 2^30,402,457 - 1, that digit is roughly 9,152,052 dec digits long. i am not wanting to waste 30k to store the smaller primes that can be stored in 128 bits. my ultimate goal is to win the prize money from eff [link]http://www.eff.org/awards/coop.php[/link]. while it is unlikely that i will achive that since i am doing this on my own, if i can learn to do this efficiantly, then i make myself more valuable for a job down the line. however, the only way that i have been able to figure out on how to do something like this, would be to create a variable sized array that would split the number up.
    Code:
        unsigned int sizeofarray;
    
    ... stuff to figureout how large the number acctually is...
    
        unsigned int array[sizeofarray];
    so if the number was say 2, then it would have an array of 1, if the number was say 2^128 -1, it would then have an array size of 4. and then write up the math functions as needed to work within these bounds. which would be a solution to making a dynamically sized variable. i just feal that there is a better answer to this.

  5. #5
    Registered User mltngpot's Avatar
    Join Date
    Jan 2006
    Posts
    5
    Quote Originally Posted by Salem
    If you're not going to do it yourself, find a bignum package like say "GMP"
    i want to do it myself. i want to learn. if i use GMP then i will learn nothing, if i look at the GMP source, i learn nothing because it is mostly assembly. other programs writen in c are barely legible because of the formating. the question that i pose has other mathmatical applications, but prime numbers are easy to find and program. so it makes for a good starting point.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    > that digit is roughly 9,152,052 dec digits long. i am not wanting to waste 30k to store the smaller primes that can be stored in 128 bits.
    See, this makes no sense at all.
    A 10M digit decimal number needs over 33M binary bits to store it, so you're looking at
    unsigned long aNumber[1038103];
    for the smallest 10M digit number before you even start.

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    there is no computer in the world that can store that as ONE numeric integer -- I've seen math packages that can work with (seemingly) infinitely large integers and that's probably what those geeks use to find that gigantic prime number.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    > if i look at the GMP source, i learn nothing because it is mostly assembly.
    Try studying the algorithms then, rather than the implementation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a snake game (ncurses)
    By Adam4444 in forum C Programming
    Replies: 11
    Last Post: 01-17-2007, 03:41 PM
  2. Passing structures to a function
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 07-13-2005, 07:13 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Weird modification to string length
    By ChwanRen in forum C Programming
    Replies: 0
    Last Post: 08-17-2003, 11:45 AM
  5. length of string etc.
    By Peachy in forum C Programming
    Replies: 5
    Last Post: 09-27-2001, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21