Java Utililty Methods Abs

List of utility methods to do Abs

Description

The list of methods to do Abs are organized into topic(s).

Method

voidabs(double[] in)
abs
int height = in.length;
for (int yy = 0; yy < height; yy++) {
    in[yy] = Math.abs(in[yy]);
double[]abs(double[] v)
Takes the absolute value of each component of an array.
double[] ans = new double[v.length];
for (int i = 0; i < v.length; i++) {
    ans[i] = Math.abs(v[i]);
return (ans);
double[][]abs(double[][] A)
absolute value
double[][] C = new double[A.length][A[0].length];
for (int i = 0; i < A.length; i++) {
    for (int j = 0; j < A[i].length; j++) {
        C[i][j] = Math.abs(A[i][j]);
return C;
byteabs(final byte x)
Get absolute value with special case to ensure value doesn't cause XORed String be the same as the input.
return (byte) Math.abs(x <= 0 ? x + 1 : x);
doubleabs(final double d)
Returns the absolute value of d (without branching).
return Double.longBitsToDouble(Long.MAX_VALUE & Double.doubleToRawLongBits(d));
doubleabs(final double value)
Return absolute value.
return (value < 0 ? -value : value);
doubleabs(final double x)
abs
return x < 0 ? -x : x;
intabs(final int pNumber)
A replacement for Math.abs , that never returns negative values.
if (pNumber == Integer.MIN_VALUE) {
    throw new ArithmeticException("int overflow: 2147483648");
return (pNumber < 0) ? -pNumber : pNumber;
floatabs(float f)
abs
if (f >= 0)
    return f;
else
    return -f;
floatabs(float value)
abs
return value >= 0.0F ? value : -value;