/** Returns true if the value is zero. * @param tolerance represent an upper bound below which the value is considered zero. */ static public boolean isZero (float value, float tolerance) { return Math.abs(value) <= tolerance; }
/** Returns true if a is nearly equal to b. The function uses the default floating error tolerance. * @param a the first value. * @param b the second value. */ static public boolean isEqual (float a, float b) { return Math.abs(a - b) <= FLOAT_ROUNDING_ERROR; }
/** Returns true if a is nearly equal to b. * @param a the first value. * @param b the second value. * @param tolerance represent an upper bound below which the two values are considered equal. */ static public boolean isEqual (float a, float b, float tolerance) { return Math.abs(a - b) <= tolerance; }
@Override public EventExecutor next() { return executors[Math.abs(idx.getAndIncrement() % executors.length)]; } }
/** Returns the distance between the given line and point. Note the specified line is not a line segment. */ public static float distanceLinePoint (float startX, float startY, float endX, float endY, float pointX, float pointY) { float normalLength = (float)Math.sqrt((endX - startX) * (endX - startX) + (endY - startY) * (endY - startY)); return Math.abs((pointX - startX) * (endY - startY) - (pointY - startY) * (endX - startX)) / normalLength; }
public String getServerId() { if (this.serverId == null) { this.serverId = String.valueOf(Math.abs(getUuid().getMostSignificantBits()) % 1000); } return this.serverId; }
public float abs(float value) { return Math.abs(value); } }
public int abs(int value) { return Math.abs(value); }
private static int randomIntFrom0to(int max) { // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml long x = System.nanoTime(); x ^= (x << 21); x ^= (x >>> 35); x ^= (x << 4); return Math.abs((int) x % max); }
private static int randomIntFrom0to100() { // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml long x = System.nanoTime(); x ^= (x << 21); x ^= (x >>> 35); x ^= (x << 4); return Math.abs((int) x % 100); }
private static int randomIntFrom0to(int max) { // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml long x = System.nanoTime(); x ^= (x << 21); x ^= (x >>> 35); x ^= (x << 4); return Math.abs((int) x % max); }
private static int randomIntFrom0to100() { // XORShift instead of Math.random http://javamex.com/tutorials/random_numbers/xorshift.shtml long x = System.nanoTime(); x ^= (x << 21); x ^= (x >>> 35); x ^= (x << 4); return Math.abs((int) x % 100); }
/** Creates a sprite with width, height, and texture region equal to the specified size. * @param srcWidth The width of the texture region. May be negative to flip the sprite when drawn. * @param srcHeight The height of the texture region. May be negative to flip the sprite when drawn. */ public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) { if (texture == null) throw new IllegalArgumentException("texture cannot be null."); this.texture = texture; setRegion(srcX, srcY, srcWidth, srcHeight); setColor(1, 1, 1, 1); setSize(Math.abs(srcWidth), Math.abs(srcHeight)); setOrigin(width / 2, height / 2); }
public void captureFloatArgument(JoinPoint tjp, float arg) { float tjpArg = ((Float) tjp.getArgs()[0]).floatValue(); if (Math.abs(tjpArg - arg) > 0.000001) { throw new IllegalStateException( "argument is '" + arg + "', " + "but args array has '" + tjpArg + "'" ); } this.lastBeforeFloatValue = arg; }
private static void assertApproximateDifference(Date lesser, Date greater, long expected) { long diff = greater.getTime() - lesser.getTime(); long variance = Math.abs(expected - diff); assertTrue("expected approximate difference of " + expected + ", but actual difference was " + diff, variance < 100); }
private static void assertNegligibleDifference(Date d1, Date d2) { long diff = Math.abs(d1.getTime() - d2.getTime()); assertTrue("difference exceeds threshold: " + diff, diff < 100); }
public void testFuzzyEqualsFinite() { for (double a : FINITE_DOUBLE_CANDIDATES) { for (double b : FINITE_DOUBLE_CANDIDATES) { for (double tolerance : FINITE_TOLERANCE_CANDIDATES) { assertEquals(Math.abs(a - b) <= tolerance, DoubleMath.fuzzyEquals(a, b, tolerance)); } } } }
@Test public void SPR9486_floatFunctionResolver() { Number expectedResult = Math.abs(-10.2f); ExpressionParser parser = new SpelExpressionParser(); SPR9486_FunctionsClass testObject = new SPR9486_FunctionsClass(); StandardEvaluationContext context = new StandardEvaluationContext(); Expression expression = parser.parseExpression("abs(-10.2f)"); Number result = expression.getValue(context, testObject, Number.class); assertEquals(expectedResult, result); }
@GwtIncompatible // #trueLog2, Math.ulp public void testLog2Accuracy() { for (double d : POSITIVE_FINITE_DOUBLE_CANDIDATES) { double dmLog2 = DoubleMath.log2(d); double trueLog2 = trueLog2(d); assertTrue(Math.abs(dmLog2 - trueLog2) <= Math.ulp(trueLog2)); } }