(Latest Revision: 04/19/2008)

### Tips On Making The Table

When working with "real" numbers you have to keep in mind problems like underflow and overflow.

When I calculate the numbers for the table I am careful about the fact that the formula for the frequency:

(eαk)/(k!)

can result in numbers that are very close to zero, and therefore very incorrect values can be created by the hardware of the computer.

To guard against error, I use "double" for the data type of all non-integers (like alpha and the frequency above). Also since what I really need to print in the table is the product of the frequency times the table size, I multiply times the table size "early" to avoid underflow. An example may illustrate:

• Next initialize

alpha <-- numberOfEltsInTable/TableSize, and
predictedValue for k==0 <-- TableSize*exp(-alpha)

• Print predictedValue under "predicted" in row 0 of the table (use directives like cout.setf(ios::fixed) and cout.setf(ios::right) and setprecision(0) and setw(4) to get the display right)

• In your loop that creates the table entries, transform the old prediction into the new one by multiplying by alpha/counterValue. [e.g

(predictedValue for k==1) <-- (predictedValue for k==0)*(alpha/1),
(predictedValue for k==2) <-- (predictedValue for k==1)*(alpha/2),
(predictedValue for k==3) <-- (predictedValue for k==2)*(alpha/3),

and so on.]

Working like that helps you stay away from really tiny values of the predicted frequency function that could cause underflow.

If you are having problems with your table display, then maybe some of these ideas will help.