@Test @Category(UnitTest.class) public void testfloat() { Assert.assertTrue("Values should be equal", FloatUtils.isEqual(1.0f, 1.0000001f, 1)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(1.0000001f, 1.0f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(1.0f, 1.0000002f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(1.0000002f, 1.0f, 1)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(1.0f, 1.0000002f, 2)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(1.0000002f, 1.0f, 2)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(Float.MIN_VALUE, Float.MAX_VALUE, 1)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(Float.MIN_VALUE, Float.MAX_VALUE, 32)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(0.0f, -0.0f, 1)); Assert.assertTrue("Values should be equal", FloatUtils.isEqual(-0.0f, 0.0f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(0.0f, -1.0f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(-1.0f, 0.0f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(1.0f, -1.0f, 1)); Assert.assertFalse("Values should not be equal", FloatUtils.isEqual(-1.0f, 1.0f, 1)); }
public static boolean isEqual(float a, float b, int bitsprecision) { if (bitsprecision >= 32 || bitsprecision < 0) { return bitsprecision == 32; } Floater fa = new Floater(a); Floater fb = new Floater(b); if (fa.neg != fb.neg) { return (fa.exp | fb.exp | fa.mant | fb.mant) == 0; } if (bitsprecision == 0) { return fa.bits == fb.bits; } int d = fa.bits - fb.bits; int bp = 1 << (bitsprecision - 1); return d <= bp && d >= -bp; }
FloatUtils { public static boolean isEqual(float a, float b, int bitsprecision) { if (bitsprecision >= 32 || bitsprecision < 0) { return bitsprecision == 32; } Floater fa = new Floater(a); Floater fb = new Floater(b); if (fa.neg != fb.neg) { return (fa.exp | fb.exp | fa.mant | fb.mant) == 0; } if (bitsprecision == 0) { return fa.bits == fb.bits; } int d = fa.bits - fb.bits; int bp = 1 << (bitsprecision - 1); return d <= bp && d >= -bp; } }
FloatUtils { public static boolean isEqual(float a, float b, int bitsprecision) { if (bitsprecision >= 32 || bitsprecision < 0) { return bitsprecision == 32; } Floater fa = new Floater(a); Floater fb = new Floater(b); if (fa.neg != fb.neg) { return (fa.exp | fb.exp | fa.mant | fb.mant) == 0; } if (bitsprecision == 0) { return fa.bits == fb.bits; } int d = fa.bits - fb.bits; int bp = 1 << (bitsprecision - 1); return d <= bp && d >= -bp; }  }
FloatUtils { public static boolean isEqual(float a, float b, int bitsprecision) { if (bitsprecision >= 32 || bitsprecision < 0) { return bitsprecision == 32; } Floater fa = new Floater(a); Floater fb = new Floater(b); if (fa.neg != fb.neg) { return (fa.exp | fb.exp | fa.mant | fb.mant) == 0; } if (bitsprecision == 0) { return fa.bits == fb.bits; } int d = fa.bits - fb.bits; int bp = 1 << (bitsprecision - 1); return d <= bp && d >= -bp; }  static boolean isEqual(float a, float b, int bitsprecision); static boolean isEqual(double a, double b, int bitsprecision); static boolean isEqual(double a, double b); static boolean isEqual(float a, float b); static boolean isEqual(float a, float b, float epsilon); static boolean isEqual(double a, double b, double epsilon); static boolean isNodata(double v, double nodata); static boolean isNotNodata(double v, double nodata); static boolean isNodata(float v, float nodata); static boolean isNotNodata(float v, float nodata); }
FloatUtils { public static boolean isEqual(float a, float b, int bitsprecision) { if (bitsprecision >= 32 || bitsprecision < 0) { return bitsprecision == 32; } Floater fa = new Floater(a); Floater fb = new Floater(b); if (fa.neg != fb.neg) { return (fa.exp | fb.exp | fa.mant | fb.mant) == 0; } if (bitsprecision == 0) { return fa.bits == fb.bits; } int d = fa.bits - fb.bits; int bp = 1 << (bitsprecision - 1); return d <= bp && d >= -bp; }  static boolean isEqual(float a, float b, int bitsprecision); static boolean isEqual(double a, double b, int bitsprecision); static boolean isEqual(double a, double b); static boolean isEqual(float a, float b); static boolean isEqual(float a, float b, float epsilon); static boolean isEqual(double a, double b, double epsilon); static boolean isNodata(double v, double nodata); static boolean isNotNodata(double v, double nodata); static boolean isNodata(float v, float nodata); static boolean isNotNodata(float v, float nodata); static final double DOUBLE_EPSILON; static final float FLOAT_EPSILON; }