Click here to Skip to main content
15,889,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How is it possible to work with numbers which exceed the limit of long long int?

For reference, I want to write a program which prints prime numbers from 0 to very large numbers (50+ digits). Is there a way to do that in C?

What I have tried:

The GNU MP Bignum Library[^]

I know that there is the GNU library, but is there a way to make it work with the standart compiler?
Posted
Updated 27-Nov-20 11:38am
Comments
KarstenK 28-Nov-20 3:50am    
one reason for libraries are that give solutions which arent yet available. So the existence of a library is often the solution for an existing problem. :-O

Simple answer, no.
If your compiler supports it, you might have a 128 bit int type which has a range of approximately 40 digits. To get to 50 you would need approximately 166 bits, but no compiler that I know of supports any integer types above 128 bits.

Bignum libraries exist to cover situations where calculations exceed the native bounds of the CPU. The nice thing about them is that they can be used on 32 and 64 bit CPUS, maybe even 16 bit and presumably will work on 128 bit CPUS if/when they become available.
 
Share this answer
 
Comments
Member 14955513 27-Nov-20 16:54pm    
What is the most simple bignum library that would allow me to do operations with large numbers? I have looked into the GNU and for a beginner like me it looks quite difficult while my time is limited to hand in the project? thank you.
Quote:
How is it possible to work with numbers which exceed the limit of long long int?

For this kind of activity, assembler is the language to use.
Here is some lecture:
A Bigint Calculator[^]
Working with Big Numbers Using x86 Instructions[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900