Precision { public static double representableDelta(double x, double originalDelta) { return x + originalDelta - x; } private  Precision(); static int compareTo(double x, double y, double eps); static int compareTo(final double x, final double y, final int maxUlps); static boolean equals(float x, float y); static boolean equalsIncludingNaN(float x, float y); static boolean equals(float x, float y, float eps); static boolean equalsIncludingNaN(float x, float y, float eps); static boolean equals(final float x, final float y, final int maxUlps); static boolean equalsIncludingNaN(float x, float y, int maxUlps); static boolean equals(double x, double y); static boolean equalsIncludingNaN(double x, double y); static boolean equals(double x, double y, double eps); static boolean equalsWithRelativeTolerance(double x, double y, double eps); static boolean equalsIncludingNaN(double x, double y, double eps); static boolean equals(final double x, final double y, final int maxUlps); static boolean equalsIncludingNaN(double x, double y, int maxUlps); static double round(double x, int scale); static double round(double x, int scale, int roundingMethod); static float round(float x, int scale); static float round(float x, int scale, int roundingMethod); static double representableDelta(double x,
                                            double originalDelta); static final double EPSILON; static final double SAFE_MIN; }
@Test public void testRepresentableDelta() { int nonRepresentableCount = 0; final double x = 100; final int numTrials = 10000; for (int i = 0; i < numTrials; i++) { final double originalDelta = FastMath.random(); final double delta = Precision.representableDelta(x, originalDelta); if (delta != originalDelta) { ++nonRepresentableCount; } } Assert.assertTrue(nonRepresentableCount / (double) numTrials > 0.9); }