Fixed type casting. Casting to double after the math loses the desired precision.