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

Cosmetics

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
role="red">/</emphasis>
int * double
⭨ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis>
double</screen>
</listitem>
<listitem>
<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
role="red">/</emphasis>
int * float
⭨ ⭩
<emphasis role="red">\</emphasis> <emphasis role="red">/</emphasis>
float</screen>
</listitem>
</orderedlist>
......@@ -245,7 +247,7 @@ Provided: double</screen>
</listitem>
<listitem>
<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>
</listitem>
</orderedlist>
......@@ -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>
</listitem>
<listitem>
......@@ -348,8 +350,9 @@ Provided: double</screen>
<m:mi>62</m:mi>
</m:msup>
</m:math>
</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">
<m:mrow>
<m:msup>
......@@ -363,13 +366,12 @@ Provided: double</screen>
<m:mi>1</m:mi>
</m:mrow>
</m:math>
</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
log.info(result);
return result;
}</programlisting>
......
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