Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

10 million digits

DarQDarQ Posts: 1,625Member
[b][red]This message was edited by DarQ at 2004-2-4 11:20:34[/red][/b][hr]
Hi

i just started a week ago coding C, and i love it already! especially the fact that what i code in winNT, can be compiled on my linux box without a problem :D But i have a question now to which i haven't found an answer yet.

today i made a thing that finds prime numbers. As the numbers grow larger, the proccess takes longer, but there is a trick for that ;)
The problem now is, that i want to exceed the storage capacity of unsigned longs.. use numbers of about 10 MILLION digits.

now, 10 million might be a bit too much for now, but an unsigned long has certainly not enough digits.

can anyone kick my in the right direction?

greets!
[size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
NEW url--> http://mark.space.servehttp.com


«1

Comments

  • BriballBriball Posts: 265Member
    The solution is NOT easy. The primitive data types are there to be used, and they have sizes that are supposed to be "reasonable". But sometimes you do have to go over the limit. A solution would be to create a struct that contains two unsigned longs in it. Then you modify your algorithm that finds prime numbers to work with this struct. Everything needs to be modified because no c runtime functions will be able to just work with your new data type.

    [code]
    struct LARGE_NUM{
    unsigned long num1;
    unsigned long num2;
    };

    [/code]

    num1 could be the primary storage area, and num2 is where the overflow bytes (the digits that don't fit into num1) go. This kind of stuff requires some knowledge of how the computer stores these data types. This can be platform specific...

  • shaolin007shaolin007 Posts: 1,018Member
    : [b][red]This message was edited by DarQ at 2004-2-4 11:20:34[/red][/b][hr]
    : Hi
    :
    : i just started a week ago coding C, and i love it already! especially the fact that what i code in winNT, can be compiled on my linux box without a problem :D But i have a question now to which i haven't found an answer yet.
    :
    : today i made a thing that finds prime numbers. As the numbers grow larger, the proccess takes longer, but there is a trick for that ;)
    : The problem now is, that i want to exceed the storage capacity of unsigned longs.. use numbers of about 10 MILLION digits.
    :
    : now, 10 million might be a bit too much for now, but an unsigned long has certainly not enough digits.
    :
    : can anyone kick my in the right direction?
    :
    : greets!
    : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : NEW url--> http://mark.space.servehttp.com
    :
    :
    :

    [green] 10 million digits in what? Decimal, hexidecimal, octal, binary?
    If decimal or any other numbering system said above is used then it's going to require [b][red]ALOT[/red][/b] of memory. Probably 10 to the what ever power(I'm not even going to figure it out) decimal converted into a binary equivalent of the greatest value you will ever need. On top of that, your variable usage would be astounding to even type by hand, so that would have to be automated also since the most a variable that I know of can hold is 80bit numbers on a PC. That's probably why those super puter's that analyze astronomical equations are so expensive because you need it to handle big numbers and be fast at the same time.

  • DarQDarQ Posts: 1,625Member

    : [code]
    : struct LARGE_NUM{
    : unsigned long num1;
    : unsigned long num2;
    : };
    :
    : [/code]

    i guess dividing such numbers would work like asm with 2 bytes or more??

    btw: i've seen something about unsigned long long's. how big are those?
    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    NEW url--> http://mark.space.servehttp.com

  • shaolin007shaolin007 Posts: 1,018Member
    [red]
    : btw: i've seen something about unsigned long long's. how big are those?
    [/red]

    64bit

    Like I said before the biggest variable type I know of is 80bit or a tbyte also a real 10 which is of course a 10byte number, but I don't remember how it would be declared in C since I have never messed with numbers that big in c or anything else in that matter.
  • askgodsaskgods Posts: 10Member
    : : [b][red]This message was edited by DarQ at 2004-2-4 11:20:34[/red][/b][hr]
    : : Hi
    : :
    : : i just started a week ago coding C, and i love it already! especially the fact that what i code in winNT, can be compiled on my linux box without a problem :D But i have a question now to which i haven't found an answer yet.
    : :
    : : today i made a thing that finds prime numbers. As the numbers grow larger, the proccess takes longer, but there is a trick for that ;)
    : : The problem now is, that i want to exceed the storage capacity of unsigned longs.. use numbers of about 10 MILLION digits.
    : :
    : : now, 10 million might be a bit too much for now, but an unsigned long has certainly not enough digits.
    : :
    : : can anyone kick my in the right direction?
    : :
    : : greets!
    : : [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    : : NEW url--> http://mark.space.servehttp.com
    : :
    : :
    : :
    :
    : [green] 10 million digits in what? Decimal, hexidecimal, octal, binary?
    : If decimal or any other numbering system said above is used then it's going to require [b][red]ALOT[/red][/b] of memory. Probably 10 to the what ever power(I'm not even going to figure it out) decimal converted into a binary equivalent of the greatest value you will ever need. On top of that, your variable usage would be astounding to even type by hand, so that would have to be automated also since the most a variable that I know of can hold is 80bit numbers on a PC. That's probably why those super puter's that analyze astronomical equations are so expensive because you need it to handle big numbers and be fast at the same time.
    :
    :


    ===========================================================


    hey...why dont u try changing a file called "limits.h" , which has the min & max values of almost all the things ( with values ) , and i have seen datatypes like "long long".

  • stoberstober Posts: 9,765Member ✭✭✭
    :
    : hey...why dont u try changing a file called "limits.h" , which has the min & max values of almost all the things ( with values ) , and i have seen datatypes like "long long".
    :
    :

    [blue]Yes, Windows OS has a "long long" data type, which is a 64-bit number. It's twice the size of a long, but doesn't even come close to holding 10,000,000 digits. There is simply no way to do that on a PC using native data types and current archetecture. Maybe, just maybe, if you go to NASA they can help you.[/blue]
  • DarQDarQ Posts: 1,625Member
    i see..

    im aware that no datatype can hold plenty digits. but if you can do 16 bits divisions on an 8 bits cpu (asm), then with C it should work as well, i hope ;)

    i will try to figure it out by using quite a few longs.
    :
    : [blue]Yes, Windows OS has a "long long" data type, which is a 64-bit number. It's twice the size of a long, but doesn't even come close to holding 10,000,000 digits. There is simply no way to do that on a PC using native data types and current archetecture. Maybe, just maybe, if you go to NASA they can help you.[/blue]
    :

    [size=5][italic][blue]Dar[RED]Q[/RED][/blue][/italic][/size]
    NEW url--> http://mark.space.servehttp.com

  • JBakerJBaker Posts: 197Member
    : [red]
    : : btw: i've seen something about unsigned long long's. how big are those?
    : [/red]
    :
    : 64bit
    :
    : Like I said before the biggest variable type I know of is 80bit or a tbyte also a real 10 which is of course a 10byte number, but I don't remember how it would be declared in C since I have never messed with numbers that big in c or anything else in that matter.
    :

    [green]
    While using a Borland compiler the correct type for an 80bit variable is a long double. 80bits is quite a large variable, its assigned value can be anywhere from 3.4 x 10-4932 to 1.1 x 10+4932.
    [/green]
    [hr]
    [blue][size=4]JBaker[/size][/blue]

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : : [red]
    : : : btw: i've seen something about unsigned long long's. how big are those?
    : : [/red]
    : :
    : : 64bit
    : :
    : : Like I said before the biggest variable type I know of is 80bit or a tbyte also a real 10 which is of course a 10byte number, but I don't remember how it would be declared in C since I have never messed with numbers that big in c or anything else in that matter.
    : :
    :
    : [green]
    : While using a Borland compiler the correct type for an 80bit variable is a long double. 80bits is quite a large variable, its assigned value can be anywhere from 3.4 x 10-4932 to 1.1 x 10+4932.
    : [/green]
    : [hr]
    : [blue][size=4]JBaker[/size][/blue]
    :
    :
    [blue]So, by that logic, say, value of 0.728672933993887857487376E+4930 will have all the 4930 digits as a significant ones? I doubt that. Mantissa is still limited to some 71 bit or so... and it is not even close to 1000 digits even...[/blue]
  • Ed HallEd Hall Posts: 395Member
    An avenue that I use when playing with large numbers is to work the digits into strings. Unfortunately, this entails writing your own math routines for the strings, and there is a great loss in memory usage, but the string length becomes the limit of the number of digits. A simple example would be to take the number 12345678901234567891123456789212345678931234567894 and multiply it by 3. This would give the math routines a bit of a challenge but all you really need to do is assign the above number to a string and then write your own routine which does the math based on each digit. For the above your routine will extract the first digit on the right, convert it to its numeric value (character 4 - 48 becomes numeral 4) and then multiply it by the 3 using normal math procedures. Capture any carry and place the converted "ones" result into the first place on the right of a second string (remember to add 48 to the new numeral before placing it in your second string). Work your way left one character at a time and you get the same result as if you were able to do direct math. Granted there is an awful waste in memory and conversion, but it is a solution.

    Take Care,
    Ed Hall

«1
Sign In or Register to comment.