Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
ef9fa08b
Commit
ef9fa08b
authored
8 months ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Better explanation
parent
7dbd0ff9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Sd1/Appendix/Exam/2024/Summer/exam.xml
+13
-7
13 additions, 7 deletions
Doc/Sd1/Appendix/Exam/2024/Summer/exam.xml
with
13 additions
and
7 deletions
Doc/Sd1/Appendix/Exam/2024/Summer/exam.xml
+
13
−
7
View file @
ef9fa08b
...
...
@@ -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:
T
he 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 t
he int literal
<code
language=
"java"
>
1000000000
</code>
gets
being converted
in
to 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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment