about to change to computing result in body of distance.Rdb
...
oddity with posX = i having to be in inner loop
allocate the answer in the body rather than requiring it to be passed to the routine