English

# Problem: DOCELL reports different results than expected when an IF structure is being used

## Description

In some cases, a DOCELL loop may report results different than what is expected.

## Cause

There is a problem with IF structures inside DOCELL loops. Occasionally, intermediate results are being internally calculated as floating point when they should be integer.

## Solution or Workaround

Workarounds include:
- ensuring that any intermediate results are indeed integer (see workaround 1).
- avoid using the temporary assignment operator (see workaround 2).
- avoid using DOCELL entirely. If there is not an accumulative operator being used, the same results can almost always be obtained using regular grid operators and loops. Also, DOCELL performance is generally less than what can be achieved by normal procedures.

An example that demonstrates the issue is the following:

Input: aa
10 10 10 10 10
5 5 5 10 10
0 0 5 10 10
n n 5 5 5
10 10 5 5 5

Input: bb
50 50 50 50 50
0 0 0 50 50
0 0 0 0 0
n n 0 0 0
50 50 0 0 0

Grid: docell
:: tmp11 := aa * (bb / 100)
:: if (0 > 1) out11 = 999
:: else out11 = tmp11
:: end
Grid:
Grid: print tmp11
5 5 5 5 5
0 0 0 5 5
0 0 0 0 0
n n 0 0 0
5 5 0 0 0

The expectation would be that all the output cells would be 0 or ND.

Workaround 1:
If the INT function is performed on the division as follows, the expected results are made:

Grid: docell
:: tmp22 := aa * int(bb / 100)
:: if (0 > 1) out22 = 999
:: else out22 = tmp22
:: end
Grid:
Grid: print out22
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
n n 0 0 0
0 0 0 0 0

Workaround 2:
If the EQUALS operator (=) is used instead, the expected results are made:

Grid: docell
:: tmp33 = aa * (bb / 100)
:: if (0 > 1) out33 = 999
:: else out33 = tmp33
:: end
Grid:
Grid: print out33
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
n n 0 0 0
0 0 0 0 0