Commit d4e1ed12 authored by Dr. Martin Goik's avatar Dr. Martin Goik


parent 9590217f
......@@ -183,23 +183,25 @@ Provided: double</screen>
<code>3.1415926</code> is of type double. We thus have:</para>
<screen>int * int * double
⭨ ⭩ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis> <emphasis
int * double
⭨ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis>
<para>Replacing the <code>double</code> literal by a a
<para>Replacing the <code>double</code> literal by a
<code>float</code> literal leaves us with an overall
<code>float</code> expression resolving the issue:</para>
<screen>radius * radius * 3.1415926<emphasis role="red">F</emphasis>
int * int * float
⭨ ⭩ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis> <emphasis
int * float
⭨ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis>
......@@ -245,7 +247,7 @@ Provided: double</screen>
<para>You are allowed to modify the method's signature.
<para>You are allowed to modify the method's return type.
Provide a solution.</para>
......@@ -322,7 +324,7 @@ Provided: double</screen>
<para>Starting from <code>46341</code> all computed squares
are simply wrong due to arithmetic overflow regardless of
their result's sign. </para>
their result's sign.</para>
......@@ -348,8 +350,9 @@ Provided: double</screen>
</inlineequation>. Choosing return type <code>long</code>
allows for a maximum value of <inlineequation>
</inlineequation> representing the method's largest possible
result. Choosing return type <code>long</code> allows for a
maximum value of <inlineequation>
<m:math display="inline">
......@@ -363,13 +366,12 @@ Provided: double</screen>
</inlineequation>which is ways larger than required. Turning
</inlineequation>being ways larger than required. Turning
the <code>int</code> into a <code language="java">long</code>
expression is easy:</para>
<programlisting language="java">static public long getSquare (int value) {
long result = value;
result *= value;
final long result = (long) value * value; // Cast: long * int expression;
return result;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment