Editing 2319: Large Number Formats

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 63: Line 63:
 
| The two most common computer {{w|Floating-point arithmetic|floating-point}} formats are the IEEE 754 {{w|Single-precision floating-point format|single-precision}} and {{w|Double-precision floating-point format|double-precision}} representations.  These are ''binary'' floating-point formats, representing numbers as the quantity ''a'' &times; 2<sup>''e''</sup>, for some fractional number ''a'' and exponent ''e''.  Both the values ''a'' and ''e'' have a fixed size in bits, and therefore a finite range.  In single-precision, ''a'' and ''e'' have (effectively) 24 and 8 bits, respectively, while in double precision the effective sizes are 53 and 11 bits.
 
| The two most common computer {{w|Floating-point arithmetic|floating-point}} formats are the IEEE 754 {{w|Single-precision floating-point format|single-precision}} and {{w|Double-precision floating-point format|double-precision}} representations.  These are ''binary'' floating-point formats, representing numbers as the quantity ''a'' &times; 2<sup>''e''</sup>, for some fractional number ''a'' and exponent ''e''.  Both the values ''a'' and ''e'' have a fixed size in bits, and therefore a finite range.  In single-precision, ''a'' and ''e'' have (effectively) 24 and 8 bits, respectively, while in double precision the effective sizes are 53 and 11 bits.
  
βˆ’
Fully representing the number 25,259,974,097,204 (in any format) requires at least 45 bits.  Therefore this number cannot be represented exactly as a single-precision float.  The closest possible representations are 0.717931628 &times; 2<sup>45</sup> and 0.717931688 &times; 2<sup>45</sup>; these work out to 25,259,973,541,888 and 25,259,975,639,040, respectively.  Of these, the one ending in 888 is considerably closer to the original, so is chosen due to {{w|rounding}}.  (Naturally these numbers are represented internally in binary, not decimal; the actual representations, in {{w|hexadecimal}}, are <tt>0.b7ca5e</tt> &times; 2<sup><tt></tt>2d</sup> and <tt>0.b7ca5f</tt> &times; 2<sup><tt></tt>2d</sup>.)
+
Fully representing the number 25,259,974,097,204 (in any format) requires at least 45 bits.  Therefore this number cannot be represented exactly as a single-precision float.  The closest possible representations are 0.717931628 &times; 2<sup>45</sup> and 0.717931688 &times; 2<sup>45</sup>; these work out to 25,259,973,541,888 and 25,259,975,639,040, respectively.  Of these, the one ending in 888 is considerably closer to the original, so is chosen due to {{w|rounding}}.  (Naturally these numbers are represented internally in binary, not decimal; the actual representations, in hexadecimal, are <tt>0.b7ca5e</tt> &times; 2<sup><tt></tt>2d</sup> and <tt>0.b7ca5f</tt> &times; 2<sup><tt></tt>2d</sup>.)
  
 
In many programming languages, the keyword to request a single-precision floating-point variable is <tt>float</tt>, while the keyword to request double-precision is <tt>double</tt>.  It is an easy mistake to make to forget about the limited precision available with type <tt>float</tt>, especially since its name sounds like what you want for "floating point".  (Had the programmer remembered to use type <tt>double</tt>, the number 25,259,974,097,204 could have been represented exactly (still in hexadecimal), as <tt>0.b7ca5e43c9a000</tt> &times; 2<sup><tt></tt>2d</sup>.)
 
In many programming languages, the keyword to request a single-precision floating-point variable is <tt>float</tt>, while the keyword to request double-precision is <tt>double</tt>.  It is an easy mistake to make to forget about the limited precision available with type <tt>float</tt>, especially since its name sounds like what you want for "floating point".  (Had the programmer remembered to use type <tt>double</tt>, the number 25,259,974,097,204 could have been represented exactly (still in hexadecimal), as <tt>0.b7ca5e43c9a000</tt> &times; 2<sup><tt></tt>2d</sup>.)

Please note that all contributions to explain xkcd may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see explain xkcd:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel | Editing help (opens in new window)