public class CMath {
private CMath() {}
/**
* Calculate the square root of a double floating-point number.
*
* @param d the double floating-point number
* @return the square root
*/
public static double sqrt(double d) {
if (d < 0)
return Double.NaN;
double err = 1e-15;
double t = d;
while (CMath.abs(t - d / t) > err * t) {
t = (d / t + t) / 2.0;
}
return t;
}
/**
* Calculate the absolute value of a double floating-point number.
*
* @param d the double floating-point number
* @return the absolute value
*/
public static double abs(double d) {
return (d < 0) ? -d : d;
}
}