Well looking at the code, the only thing visible to me is to reduce the casting that is used.
However, i noticed that the reason you get the right answer is because of the casting. As you cast, you lose the precision and you come close to the approximate answer.
This was my analysis, you...