+ /**
+ * Return the square root of a value. If the value is negative, zero is returned.
+ * This is safer in cases where rounding errors might make a value slightly negative.
+ *
+ * @param d the value of which the square root is to be taken.
+ * @return the square root of the value.
+ */
+ public static double safeSqrt(double d) {
+ if (d < 0) {
+ if (d < 0.01) {
+ log.warn(1, "Attempting to compute sqrt(" + d + ")");
+ }
+ return 0;
+ }
+ return Math.sqrt(d);
+ }
+
+
+