Use type generic math functions

CGFloat will be a double on 64-bit architectures.