PS: If I remember correctly, multiplication, especially with doubles, is quite slow (involves quite a few cycles). So you might consider bitshifting instead of doing multiplication or division. Bitshifting is a single clock cycle operation and doesn't cause problems in the instruction pipeline, so multiple shifts can be executed in parallel. Anyhow.. it is just something to keep in the back of your mind.. doesn't need to be implemented now.