List of usage examples for org.apache.commons.math4.util FastMath abs
public static double abs(double x)
From source file:com.ericbarnhill.arrayMath.ArrayMath.java
/** * In-place element-wise {@code abs} of a {@code double[]}. Returns reference to first passed array. */*from w ww.jav a 2 s . c o m*/ * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] abs(double[] f) { final int fi = f.length; for (int i = 0; i < fi; i++) { f[i] = FastMath.abs(f[i]); } return f; }
From source file:RealFunctionValidation.java
public static SummaryStatistics assessAccuracy(final Method method, final DataInputStream in, final DataOutputStream out) throws IOException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (method.getReturnType() != Double.TYPE) { throw new IllegalArgumentException("method must return a double"); }//from w ww . j a v a2 s.c o m final Class<?>[] types = method.getParameterTypes(); for (int i = 0; i < types.length; i++) { if (!types[i].isPrimitive()) { final StringBuilder builder = new StringBuilder(); builder.append("argument #").append(i + 1).append(" of method ").append(method.getName()) .append("must be of primitive of type"); throw new IllegalArgumentException(builder.toString()); } } final SummaryStatistics stat = new SummaryStatistics(); final Object[] parameters = new Object[types.length]; while (true) { try { for (int i = 0; i < parameters.length; i++) { parameters[i] = readAndWritePrimitiveValue(in, out, types[i]); } final double expected = in.readDouble(); if (FastMath.abs(expected) > 1E-16) { final Object value = method.invoke(null, parameters); final double actual = ((Double) value).doubleValue(); final double err = FastMath.abs(actual - expected); final double ulps = err / FastMath.ulp(expected); out.writeDouble(expected); out.writeDouble(actual); out.writeDouble(ulps); stat.addValue(ulps); } } catch (EOFException e) { break; } } return stat; }
From source file:com.ericbarnhill.arrayMath.ArrayMath.java
/** * Element-wise {@code abs} of a {@code double[]}. Returns deep copy. *// ww w . ja va 2 s . com * @param f {@code double[]} array. * @return {@code double[]} array. * * @since 0.1 */ public static double[] absC(double[] f) { final int fi = f.length; double[] h = new double[fi]; for (int i = 0; i < fi; i++) { h[i] = FastMath.abs(f[i]); } return h; }