@Test public void testTrimDecimalFractionDigits() { assertEquals(-61.5, trimDecimalFractionDigits(-61.50000000000001, 4, 12), 0); assertEquals(-61.5, trimDecimalFractionDigits(-61.50000000000001, 4, 13), 0); assertEquals(-61.50000000000001, trimDecimalFractionDigits(-61.50000000000001, 4, 14), 0); assertEquals(-61.50000010000001, trimDecimalFractionDigits(-61.50000010000001, 4, 10), 0); assertEquals(-61.5, trimDecimalFractionDigits(-61.50000000000000, 4, 15), 0); }
public static double trimDecimalFractionDigits(final double value, final int maxULP, int n) { double lower = value; double upper = value; n = countDecimalFractionDigits(value) - n; if (n > 0) { for (int i=0; i<maxULP; i++) { if (countDecimalFractionDigits(lower = previous(lower)) <= n) return lower; if (countDecimalFractionDigits(upper = next (upper)) <= n) return upper; } } return value; }
XMath { public static double trimDecimalFractionDigits(final double value, final int maxULP, int n) { double lower = value; double upper = value; n = countDecimalFractionDigits(value) - n; if (n > 0) { for (int i=0; i<maxULP; i++) { if (countDecimalFractionDigits(lower = previous(lower)) <= n) return lower; if (countDecimalFractionDigits(upper = next (upper)) <= n) return upper; } } return value; } }
XMath { public static double trimDecimalFractionDigits(final double value, final int maxULP, int n) { double lower = value; double upper = value; n = countDecimalFractionDigits(value) - n; if (n > 0) { for (int i=0; i<maxULP; i++) { if (countDecimalFractionDigits(lower = previous(lower)) <= n) return lower; if (countDecimalFractionDigits(upper = next (upper)) <= n) return upper; } } return value; } private  XMath(); }
XMath { public static double trimDecimalFractionDigits(final double value, final int maxULP, int n) { double lower = value; double upper = value; n = countDecimalFractionDigits(value) - n; if (n > 0) { for (int i=0; i<maxULP; i++) { if (countDecimalFractionDigits(lower = previous(lower)) <= n) return lower; if (countDecimalFractionDigits(upper = next (upper)) <= n) return upper; } } return value; } private  XMath(); static double pow10(final double x); static strictfp double pow10(final int x); static int sgn(final double x); static int sgn(final float x); static int sgn(long x); static int sgn(int x); static short sgn(short x); static byte sgn(byte x); static double roundIfAlmostInteger(final double value, int maxULP); static double trimDecimalFractionDigits(final double value, final int maxULP, int n); static int countDecimalFractionDigits(final double value); static float toNaN(int index); static synchronized int primeNumber(final int index); static int[] divisors(int number); }
XMath { public static double trimDecimalFractionDigits(final double value, final int maxULP, int n) { double lower = value; double upper = value; n = countDecimalFractionDigits(value) - n; if (n > 0) { for (int i=0; i<maxULP; i++) { if (countDecimalFractionDigits(lower = previous(lower)) <= n) return lower; if (countDecimalFractionDigits(upper = next (upper)) <= n) return upper; } } return value; } private  XMath(); static double pow10(final double x); static strictfp double pow10(final int x); static int sgn(final double x); static int sgn(final float x); static int sgn(long x); static int sgn(int x); static short sgn(short x); static byte sgn(byte x); static double roundIfAlmostInteger(final double value, int maxULP); static double trimDecimalFractionDigits(final double value, final int maxULP, int n); static int countDecimalFractionDigits(final double value); static float toNaN(int index); static synchronized int primeNumber(final int index); static int[] divisors(int number);  }