Values larger than 2^64


If a register is 64 bits wide then the maximum value that can be stored in that register is 2^64 - 1 . How does that work with a value larger than 2^64 like a double. The calculator on Win 7 can do large calculations like you can type in 2^1000 and it will give anwser in scientific notation , how is that possible? I don't understand how the range of a 64 bit unsigned integer is 2^64 - 1 but for a double it's < 1.8e301 . Checked wikipedia but didn't really understand it's explanation.

Say a data type such as a double is 8 bytes , why is its range not the same as an 8 byte integer. Given the range of a double does that mean it can store a number up to 300 decimal places? I don't know about this -> I read somewhere that it would require like 1024 bits to do that.

Can someone explain this to me ?
Well, think of it this way- scientific notation does not actually recall all of the values after the howevermany that are displayed. It just record the number of zeros that technically should postcede or precede the other numbers. So it's still an integer, but includes an arbitrary "number of zeros."

In most cases they aren't all zeros after the first 10 digits . How are calculations done with a large number such that one like that?
Well, it simply rounds off the 11th and sets the rest to be zeros. This is why doubles aren't entire accurate, and have a margin of error.
The floating point types internally store two separate parts, one holding the digits of the number, and the other part indicates how many positions the decimal point should be shifted to the left or to the right to give the true value.

Type float usually holds about 7 decimal digits and double about 15 decimal digits. These are approximations as internally the values are binary rather than decimal.

So if i had a number say 2^100 which is 1267650600228229401496703205376
and represented that as a double which in vs prints to 1.26765e20 means after the first 5 digits all are 20 0 s?
Yes. They are all assumed to be 0s.
Hence why using large doubles tends to result in extreme error.
So if i had a number say 2^100 which is 1267650600228229401496703205376
Well, internally the value will be stored in binary, so it would probably just store the digit '1' and an exponent value of 100. Meaning 1 with the binary point (analogous to a decimal point) shifted 100 places.

If you want to check how inaccurate is working with doubles, try something like
int main()
double d=2^100,d1=2^100-10^5;

Don't expect the answer to make sense
Topic archived. No new replies allowed.