untemplate nearest to use doubles
move sqrt and invSqrt implementations to bottom