# Rule 03. Numeric Types and Operations (NUM)

• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:
• Page:

## Risk Assessment Summary

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

NUM00-JMediumUnlikelyMedium

P4

L3

NUM01-JMediumUnlikelyMedium

P4

L3

NUM02-JLowLikelyMedium

P6

L2

NUM03-JLowUnlikelyMedium

P2

L3

NUM04-JLowProbableHigh

P2

L3

NUM07-JLowProbableMedium

P4

L3

NUM08-JLowProbableMedium

P4

L3

NUM09-JLowProbableLow

P6

L2

NUM10-JLowProbableLow

P6

L2

NUM11-JLowLikelyMedium

P6

L2

NUM12-JLowUnlikelyMedium

P2

L3

NUM13-JLowUnlikelyMedium

P2

L3

NUM14-JLowProbableMedium

P4

L3

1. Here's a snippet I just ran into:

`double value = Math.ceil( 60070 / 57750);`

So what is value? Unfortunately it is not 2 but 1.

The division is cast to int and Math.ceil returns the same value if its input arg is an int. Generally, any division's result does not produce a double if the operands are integers.

A simple fix is to cast the divisor to double/float -

`double value = Math.ceil( 60070 / (double) 57750);`

Can someone add an example and delete this comment?

2. Fell into this trap wherein auto-boxing does not promote the int to Long but to Integer instead and the if condition is never true:

```Set<Long> groupList = new HashSet<Long>();

if (groupList.contains(-1)) {
// ...
}```

GOOD CODE with '1L'

```Set<Long> groupList = new HashSet<Long>();
if (groupList.contains(-1L)) {
// ...
}```

Do we have a rule for this?

Related: http://stackoverflow.com/questions/12588039/list-of-longs-how-do-you-check-if-it-contains-a-value