# SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

# Differences

This shows you the differences between two versions of the page.

 teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor58 [2018/01/20 13:42]Günter Kniesel teaching:labs:mdse:2013:bug_descriptions:jt-bug-cor58 [2018/05/09 01:59] (current) Both sides previous revision Previous revision 2018/01/20 13:42 Günter Kniesel 2018/01/20 13:42 Günter Kniesel 2018/01/20 13:41 Günter Kniesel 2017/08/31 18:53 external edit2013/11/24 23:38 cheng.fang 2013/11/24 23:38 cheng.fang created Next revision Previous revision 2018/01/20 13:42 Günter Kniesel 2018/01/20 13:42 Günter Kniesel 2018/01/20 13:41 Günter Kniesel 2017/08/31 18:53 external edit2013/11/24 23:38 cheng.fang 2013/11/24 23:38 cheng.fang created Line 1: Line 1: + ====== Bug Cor 58 ====== + + ===== Inspired by ===== + + * [[http://​findbugs.sourceforge.net/​bugDescriptions.html#​ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL | ICAST: Integral value cast to double and then passed to Math.ceil (ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL)]] + + ===== Original Description ===== + + "This code converts an integer value (e.g., int or long) to a double precision floating point number and then passes the result to the Math.ceil() function, which rounds a double to the next higher integer value. This operation is useless, since converting an integer to a double should give a number with no fractional part. It is likely that the operation that generated the value to be passed to Math.ceil was intended to be performed using double precision floating point arithmetic."​ -- 2013-11-24 ​ + + ===== Detailed Description ===== + + The cast from an int to a double yields a double with no fractional part. Thus passing the resulting double to the Math.ceil() function makes no sense -- ceiling such a value always yields the same number. ​ + + So the obvious treatments of this bug are + * to remove the Math.ceil() operation (by an automated fix) or + * to alert the developer that the original integer value might have better been generated by using double precision floating point arithmetic (manually). ​ + + ===== Sample Problem Scenario ===== + + + public void wrong1() { + int i = 1; + Math.ceil((double) i); + } + ​ + + + public void wrong2(int i) { + Math.ceil((double) i); + } + ​ + + + public class IntValueMathCeil{ + private int x = 0; + public void wrong3() { + int i = 10; + x = Math.ceil((double) i); + } + } + ​ + + ===== Sample Counter Scenario ===== + + + ===== Sample Fix ===== + + + public void wrong1() { + int i = 1; + } + ​ + + + public class IntValueMathCeil{ + private int x = 0; + public void wrong3() { + int i = 10; + x = i; + } + } + ​ + + ===== Evaluation Results ===== + + ^  Benchmark project ​ ^  Precision ​             ^^^  Recall ​               ^^^ + |                     ​| ​ FB    |  JT    |  Delta  |  FB    |  JT    |  Delta | + |  Project ...        |  ...%  |  ...%  |  ...%   ​| ​ ...%  |  ...%  |  ...%  |  ​ + |  Project ...        |  ...%  |  ...%  |  ...%   ​| ​ ...%  |  ...%  |  ...%  | + FB = FindBugs, JT = JTransformer,​ Delta = JTransformer - FindBugs +