Tabnine Logo
Math.abs
Code IndexAdd Tabnine to your IDE (free)

How to use
abs
method
in
java.lang.Math

Best Java code snippets using java.lang.Math.abs (Showing top 20 results out of 66,933)

origin: libgdx/libgdx

@Override
public boolean epsilonEquals (final Vector3 other, float epsilon) {
  if (other == null) return false;
  if (Math.abs(other.x - x) > epsilon) return false;
  if (Math.abs(other.y - y) > epsilon) return false;
  if (Math.abs(other.z - z) > epsilon) return false;
  return true;
}
origin: libgdx/libgdx

/** 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;
}
origin: libgdx/libgdx

/** 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;
}
origin: libgdx/libgdx

/** 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;
}
origin: netty/netty

  @Override
  public EventExecutor next() {
    return executors[Math.abs(idx.getAndIncrement() % executors.length)];
  }
}
origin: libgdx/libgdx

/** 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;
}
origin: spring-projects/spring-framework

public String getServerId() {
  if (this.serverId == null) {
    this.serverId = String.valueOf(Math.abs(getUuid().getMostSignificantBits()) % 1000);
  }
  return this.serverId;
}
origin: spring-projects/spring-framework

  public float abs(float value) {
    return Math.abs(value);
  }
}
origin: spring-projects/spring-framework

public int abs(int value) {
  return Math.abs(value);
}
origin: ReactiveX/RxJava

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);
}
origin: ReactiveX/RxJava

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);
}
origin: ReactiveX/RxJava

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);
}
origin: ReactiveX/RxJava

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);
}
origin: libgdx/libgdx

/** 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);
}
origin: spring-projects/spring-framework

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;
}
origin: spring-projects/spring-framework

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);
}
origin: spring-projects/spring-framework

private static void assertNegligibleDifference(Date d1, Date d2) {
  long diff = Math.abs(d1.getTime() - d2.getTime());
  assertTrue("difference exceeds threshold: " + diff, diff < 100);
}
origin: google/guava

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));
   }
  }
 }
}
origin: spring-projects/spring-framework

@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);
}
origin: google/guava

@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));
 }
}
java.langMathabs

Javadoc

Returns the absolute value of the argument.

Special cases:

  • abs(-0.0) = +0.0
  • abs(+infinity) = +infinity
  • abs(-infinity) = +infinity
  • abs(NaN) = NaN

Popular methods of Math

  • min
    Returns the smaller of two long values. That is, the result is the argument closer to the value of L
  • max
    Returns the greater of two long values. That is, the result is the argument closer to the value of L
  • round
    Returns the closest int to the argument, with ties rounding up. Special cases: * If the argument is
  • pow
    Returns the value of the first argument raised to the power of the second argument. Special cases: *
  • sqrt
    Returns the correctly rounded positive square root of a double value. Special cases: * If the argume
  • ceil
    Returns the smallest (closest to negative infinity) double value that is greater than or equal to th
  • floor
    Returns the largest (closest to positive infinity) double value that is less than or equal to the ar
  • random
    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returne
  • sin
    Returns the trigonometric sine of an angle. Special cases: * If the argument is NaN or an infinit
  • cos
    Returns the trigonometric cosine of an angle. Special cases: * If the argument is NaN or an infin
  • log
    Returns the natural logarithm (base e) of a doublevalue. Special cases: * If the argument is NaN
  • exp
    Returns Euler's number e raised to the power of a double value. Special cases: * If the argument
  • log,
  • exp,
  • toRadians,
  • atan2,
  • log10,
  • acos,
  • tan,
  • toDegrees,
  • atan

Popular in Java

  • Reactive rest calls using spring rest template
  • runOnUiThread (Activity)
  • compareTo (BigDecimal)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • ImageIO (javax.imageio)
  • IOUtils (org.apache.commons.io)
    General IO stream manipulation utilities. This class provides static utility methods for input/outpu
  • Join (org.hibernate.mapping)
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now