Skip to content
Snippets Groups Projects
Commit ef9fa08b authored by Goik Martin's avatar Goik Martin
Browse files

Better explanation

parent 7dbd0ff9
No related branches found
No related tags found
No related merge requests found
......@@ -167,11 +167,11 @@ System.out.println(1000000000 - 1000000000 + 0.000000001);</programlisting></td>
byte <code language="java">double</code> cannot express enough
digits for expressing this.</para>
<para>Longer answer: The int literal <code
language="java">1000000000</code> being converted to a <code
language="java">double</code> value is being represented as 8 byte
IEEE 754. Due to its inherently limited precision the above sums
gets truncated. We consider:</para>
<para>Longer answer: For summing up the int literal <code
language="java">1000000000</code> gets being converted into a
<code language="java">double</code> value being represented as 8
byte IEEE 754. Due to its inherently limited precision the above
sums gets truncated. We consider:</para>
<informaltable border="1">
<tr>
......@@ -185,10 +185,16 @@ System.out.println(1000000000 - 1000000000 + 0.000000001);</programlisting></td>
<td valign="top"><screen>true</screen></td>
</tr>
<tr>
<td valign="top"><programlisting language="java">System.out.println(1000000000.0 == 1000000000 + 0.000000001);</programlisting></td>
<td valign="top"><screen>true</screen></td>
</tr>
</informaltable>
<para>Thus in 8 byte IEEE 754 representation both <code
language="java">1000000000</code> and the expression <code
language="java">1000000000.0</code> and the expression <code
language="java">1000000000 + 0.000000001</code> amount to the
exact same value. Evaluating from left to right we thus
have:</para>
......@@ -196,7 +202,7 @@ System.out.println(1000000000 - 1000000000 + 0.000000001);</programlisting></td>
<itemizedlist>
<listitem>
<para><code language="java">1000000000 + 0.000000001 -
1000000000</code> = <code language="java">1000000000 -
1000000000</code> = <code language="java">1000000000.0 -
1000000000</code> = <code language="java">0.0</code>.</para>
</listitem>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment