MathUtil { public static long round(double v) { long result = Math.round(v); if (v < 0.0 && (result - v) == 0.5) { return result - 1; } return result; } private  MathUtil(); static int findMaxIndex(double[] array); static void complexConjugate(double[] data); static void complexConjugateInPlace(FieldMatrix<Complex> matrix); static double[] multiplyArrays(double[] array1, double[] array2); static double[] multiplyArrays(double[] array1, int start1, double[] array2, int start2, int length); static double[] multiplyArrays(double[] array1, int start1, double[] array2, int start2, int length, double[] result, int resultStart); static double[] multiplyComplexArrays(double[] array1, double[] array2); static double[] multiplyComplexArrays(double[] array1, int start1, double[] array2, int start2, int length); static void arrayMultiplyMatricesInPlace(FieldMatrix<Complex> matrix1, final FieldMatrix<Complex> matrix2); static double[] multiplyComplexArrays(double[] array1, int start1, double[] array2, int start2, int length, double[] result, int resultStart); static FieldMatrix<Complex> fastFourierTransform2D(RealMatrix input, DftNormalization normalization, TransformType type); static FieldMatrix<Complex> fastFourierTransform2D(FieldMatrix<Complex> input, DftNormalization normalization, TransformType type); static void fastFourierTransform2DInPlace(FieldMatrix<Complex> input, DftNormalization normalization, TransformType type); static void fftShiftInPlace(FieldMatrix<T> input); static long round(double v); static double[] vectorize(double[] source, int width, int height); static double[] vectorize(double[] source, int width, int height, int destWidth, int destHeight); static double[] shiftDimensions(double[] source, int width, int height);  }
@Test public void testRound() { assertEquals("round 0.5", 1L, MathUtil.round(0.5)); assertEquals("round -0.5", -1L, MathUtil.round(-0.5)); assertEquals("round 50.5", 51L, MathUtil.round(50.5)); assertEquals("round -50.5", -51L, MathUtil.round(-50.5)); assertEquals("round +Infinity", Long.MAX_VALUE, MathUtil.round(Double.POSITIVE_INFINITY)); assertEquals("round -Infinity", Long.MIN_VALUE, MathUtil.round(Double.NEGATIVE_INFINITY)); assertEquals("round NaN", 0L, MathUtil.round(Double.NaN)); }