Use the apache maths library for this