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

intabs(int x)
abs
if (x < 0)
    return -x;
return x;
longabs(long index)
abs
long negbit = index >> 63;
return (index ^ negbit) - negbit;
voidAbs(Object in)
Abs
if (in == null)
    return;
if (in instanceof double[]) {
    double[] inn = (double[]) in;
    for (int i = 0, s = inn.length; i < s; i++) {
        double x = inn[i];
        inn[i] = (x > 0 ? x : -x);
} else {
    for (int i = 0, s = ((Object[]) in).length; i < s; i++)
        Abs(((Object[]) in)[i]);
shortabs(short x)
Returns the absolute value of a short value
x *= x < 0 ? -1 : 1;
return x;
double[][]abs2(double[][] IN)
Returns the squared absolute value of a 2d array (complex).
int H = IN.length;
int W = IN[0].length / 2;
double[][] OUT = new double[H][W];
for (int i = 0; i < H; i++) {
    OUT[i] = abs2(IN[i], 1);
return OUT;
float[]abs2(float[] f)
Computes the power spectrum from FFT data taking into account even/odd length arrays refer to JTransforms documentation for layout of the FFT data
int n = f.length;
float[] ps = new float[n / 2 + 1];
ps[0] = (f[0] * f[0]) / (n * n);
if (n % 2 == 0) {
    for (int k = 1; k < n / 2; k++) {
        ps[k] = f[2 * k] * f[2 * k] + f[2 * k + 1] * f[2 * k + 1];
    ps[n / 2] = f[1] * f[1];
...
doubleabs_fractional(double number)
abfractional
double fr = fractional(number);
if (fr >= 0.0)
    return fr;
fr += 1.0;
if (fr >= 1.0) 
    return 0.0;
return fr;
doubleabs_min(double a, double b)
abmin
if (Math.abs(a) > Math.abs(b)) {
    return Math.signum(a) * b;
} else {
    return a;
doubleabsAngleDifference(double angle1Radians, double angle2Radians)
abs Angle Difference
double diff = angle1Radians - angle2Radians;
while (diff > Math.PI)
    diff -= PI2;
while (diff < -Math.PI)
    diff += PI2;
return Math.abs(diff);
doubleabsApproximation(double x, double M)
abs Approximation
return huberPenaltyFunction(x, M) / (2 * M);