# SDA SE Wiki

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

### Sidebar

• MDSE 2013 • Nice guys  • Methodology • Bug descriptions • Points-to Analysis • Final presentation # Bug Cor 58

## 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

<code Java> public void wrong1() {

```int i = 1;
Math.ceil((double) i);
}```

</Code>

<code Java> public void wrong2(int i) {

```Math.ceil((double) i);
}```

</Code>

<code Java> public class IntValueMathCeil{

```private int x = 0;
public void wrong3() {
int i = 10;
x = Math.ceil((double) i);
}```

} </Code>

## Sample Fix

<code Java> public void wrong1() {

```int i = 1;
}```

</Code>

<code Java> public class IntValueMathCeil{

```private int x = 0;
public void wrong3() {
int i = 10;
x = i;
}```

} </Code>

## Evaluation Results

Benchmark project Precision Recall
FB JT Delta FB JT Delta
Project … …% …% …% …% …% …%
Project … …% …% …% …% …% …%

FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs 