Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why double.MaxValue is larger than long.MaxValue?

Tags:

double

People also ask

Why double is longer than long?

A simple answer is that double is only accurate to 15-16 total digits, as opposed to long which (as an integer type) has an absolute accuracy within an explicit digit limit, in this case 19 digits. (Keep in mind that digits and values are semantically different.)

Is double bigger than Long Java?

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.

Which is bigger long or double C#?

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.

What is larger than a double?

Type long double is a floating point type that is larger than or equal to type double . Microsoft-specific: The representation of long double and double is identical. However, long double and double are treated as distinct types by the compiler.


It uses a different representation (floating point) using exponents and mantissa

For details see IEEE754


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.


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.


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.