One final comment:

If you're trying to calculate variance and standard deviation, you don't divide by num, you divide by (num - 1).

I forget why you do this, but variance and st.dev. are always over the number of samples minus one.