fonfonx
fonfonx

Reputation: 1465

Double precision - Max value

I have a pretty silly question on double precision. I have read that a double (in C for example) is represented on 64 bits, but I have also read that the maximum value that can be represented by a double is approximately 10^308. How can 10^308 be represented with only 64 bits?

Upvotes: 1

Views: 6444

Answers (3)

chmike
chmike

Reputation: 22134

It will not hold the 308 digits of the 10^308 number. The double precision number holds the exponent and a limited number of digits.

See https://en.wikipedia.org/wiki/IEEE_floating_point (english) http://fr.wikipedia.org/wiki/IEEE_754 (french) for a detailed description of floating points encoding in memory.

Upvotes: 3

Finn Årup Nielsen
Finn Årup Nielsen

Reputation: 6726

There is an exponent in the bit pattern of the 64 bits floating point IEEE numbers. In Python I compute the following:

>>> import numpy as np
>>> 2**(-52) == np.finfo(np.float64).eps
True
>>> np.finfo(np.float64).max
1.7976931348623157e+308
>>> (2-2**(-52)) * 2**(2**10-1)
1.7976931348623157e+308
>>> (2-2**(-52)) * 2**(2**10-1) == np.finfo(np.float64).max
True

So it is a bit more than 10^308. The "2**(2**10-1)" is the exponent part. See also https://en.wikipedia.org/wiki/Double-precision_floating-point_format

Upvotes: 1

Arjun Sreedharan
Arjun Sreedharan

Reputation: 11453

According to C standard, there are three floating point types: float, double, and long double, and the value representation of all floating-point types are implementation defined.

Most compilers however do follow the binary64 format, as specified by the IEEE 754 standard.

This format has:

  • 1 sign bit
  • 11 bits for exponent
  • 52 bits for mantissa

To find the largest value double can hold, you should check the DBL_MAX defined in the header <float.h>. It will be approximately 1.8 × 10308 for implementations using binary64 IEEE 754 standard.

Upvotes: 2

Related Questions