Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We use variables to store things like phrases, numbers in programming. And I want to know among all the programming languages and its variables, what is the largest number a variable can store ?

And What if programmer needs to store a larger number than the largest number of the variable can store ?
Posted

There is no absolute limit: BigInteger structure[^]
 
Share this answer
 
Comments
M­­ar­­­­k 18-Mar-14 9:15am    
Wow.. Does that mean we can use extremely large numbers like 10 million light years in nano meters with BigInteger ? doesn't it ? has a limit ?
OriginalGriff 18-Mar-14 9:32am    
It has a limit, yes - but it's an arbitrary limit based on the memory capacity of your PC.
So yes, it can, easily:
BigInteger lightYearInMetres = BigInteger.Parse("9460730472580800");
BigInteger nanoMetresInMetre = BigInteger.Parse("1000000000");
BigInteger TenMillionLightYearsInNanoMetres = nanoMetresInMetre * lightYearInMetres * 10000000;
Console.WriteLine(TenMillionLightYearsInNanoMetres);
Gives:
94607304725808000000000000000000
And that isn't that big a number at all! You can fit
340282366920938463463374607431768211456
in just 128 bits!

M­­ar­­­­k 18-Mar-14 9:37am    
I see. I really didnt calculate it before I ask.. sorry about that :) I just wanted to know if I can store extremely large numbers with BigInteger.. Thanks..

I am assuming you are talking about integers.
'Standard' integer types could represent 'largest' numbers according to their size, namely 2^size-1.
So you have, typically:
size (bits)     largest number
       8                   255
      16                 65535 
      32            4294967295
      64  18446744073709551615
      ...

However, some languages provides big integer data types (other languages could have libraries for the same purpose), 'theoretically not bounded' (see, for instance, this Stack Overflow question: Is there an upper bound to BigInteger?[^]).

Quote:
And What if programmer needs to store a larger number than the largest number of the variable can store ?
If possible, he/she defines its own datatype to cope with the number (or make some assumptions for simplify the problem and 'reduce' such number). Of course, together with the datatype the programmer has to implement all the operation he need to perform with it.
 
Share this answer
 
Comments
M­­ar­­­­k 18-Mar-14 9:15am    
Nah, Im not talking about integers.. Im talking about all the variables that can store numbers as numbers.. not strings.. :) In my knowledge double is the variable type which supports for the largest number, and no more.. OriginalGriff has commented about something named BigInteger :D Seems like it goes to the infinity..
CPallini 18-Mar-14 9:25am    
Doubles, like integers represent numbers with strings of bits, of course.
The largest Big Integer number goes as close to infinite as 255 does. :-)
M­­ar­­­­k 18-Mar-14 9:26am    
goes as close to infinity as 255 does ?? what did u mean by this o_O I don't get it !
CPallini 18-Mar-14 9:29am    
The largest Big Integer number is finite. The distance between any finite number and infinite is, well, infinite.
M­­ar­­­­k 18-Mar-14 9:37am    
Ah. I got it.. And now I wannna know if I can store a number like 10 million light years in nano meters in BigInteger variable ? :)

946080e27

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