both of them hold 8 bytes, but how come the max value for double is much greater than the max value of long? there is a finite number of bits available, so how could you reach greater numbers with floating point variables?
相关问题
- Do the Java Integer and Double objects have unnece
- How do I cast a double to an int?
- IFormatProvider scientific conversion from double
- Jquery: Prevent reloading page when pressing input
- Finding double-spaces in a string - Python
相关文章
- 关于C#中 float、double、decimal 的运算不精确的问题。
- How can I convert a OLE Automation Date value to a
- Macro or function to construct a float (double) fr
- Math.Max vs Enumerable.Max
- C# Casting to a decimal
- What are the actual ranges of floating point and d
- Print Double as Int - if not a Double value
- String to Double in XCode 6's Swift [duplicate
Because floating-point representation is of lower precision. While
long
type can represent all integer numbers in the range from its minimum to maximum,double
type can only represent some of it.Since they occupy same amount of bits, the amount of numbers each is capable to express are nearly equal (actually,
double
can represent fewer numbers). Just the paces between these numbers are different.Floating point numbers consist of a mantissa and an exponent, and the value of a floating point number is:
mantissa * 2exponent
The exponent in a Double is 11 bits, so the maximum value is of the magnitude 2211 - 1 = 21024, which is way more than the magnitude of a 64-bit signed double, which is 263-1.
A double has something called an exponent, which is basically just a scaling factor. This allows the range of double to be much greater, but at the cost of precision.
A long is a simple integer value with no scaling factor.
It uses a different representation (floating point) using exponents and mantissa
For details see IEEE754