# Thread: changing word length

1. ## 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. 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. 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. 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. 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. > 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. 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. > 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