It's known that in .NET size of both long and double is 8 bytes. However, double can store significantly larger number than long. How can it be, considering that double also needs to store data on digits after decimal point?
Shorter version of the question:
Math.Pow(2, 64) == long.MaxValue Math.Pow(2, 64) < double.MaxValue
Int64 (aka long): A signed integer with 64 bits (8 bytes) of space available. Single (aka float): A 32-bit floating point number. Double (aka double): A 64-bit floating-point number. Decimal (aka decimal): A 128-bit floating-point number with a higher precision and a smaller range than Single or Double.
The value of this constant is positive 1.7976931348623157E+308.
Values range Furthermore, the data type long stores whole numbers from 9223372036854775808 to 9223372036854775807. On the other hand, double stores values from 1.7e-308 to 1.7e+038.
The biggest/largest integer that can be stored in a double without losing precision is the same as the largest possible value of a double. That is, DBL_MAX or approximately 1.8 × 10308 (if your double is an IEEE 754 64-bit double). It's an integer.
double is floating point number. Whitch bassicaly meams that it as the number stored in double gets bigger it's beeing rouned, and the least significiant part is being dismissed.
For example in double when you have a number like 100 billion. It might be exactly 100 000 000 000 or it might be 100 000 000 000,000 000 000 000 000 001
Short answer double only stores the most significant figure and not all the digits that could be in the number. e.g. if you have a double > max value of long it will not be storing any information for digits after the decimal point or any of the figure just to the left of the deciaml point.
For all details see What every computer scientist should know about Floating-Point Arithmetic
Integer based types have whole number ranges from -2^(n-1)2 ... 2^(n-1)-1 (signed), or 0 ... 2^n-1 (unsigned).
Fixed point variables are the same as integer based types, only with a constant factor (e.g. for 0.01: 0.01*(0...2^n-1)).
Floating point variables (float and double) in any language use a few bits for the exponent and the rest for the number before the exponent. They are less accurate (x+1 might equal x, is x is a very large number), but have a much larger range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With