Example usage for java.lang Math abs

List of usage examples for java.lang Math abs

Introduction

In this page you can find the example usage for java.lang Math abs.

Prototype

@HotSpotIntrinsicCandidate
public static double abs(double a) 

Source Link

Document

Returns the absolute value of a double value.

Usage

From source file:Main.java

public static Bitmap divide(Bitmap bitmap1, Bitmap bitmap2) {
    double alpha = Double.MIN_VALUE;
    int width = bitmap1.getWidth();
    int height = bitmap1.getHeight();
    Bitmap grayBitmap1 = toGrayScale(bitmap1);
    Bitmap grayBitmap2 = toGrayScale(bitmap2);
    Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            int value1 = Color.blue(grayBitmap1.getPixel(x, y));
            int value2 = Color.blue(grayBitmap2.getPixel(x, y));
            //                int resultValue = (int) (Math.abs((Math.log((value1 + alpha)/(value2 + alpha))) * 1000));
            int resultValue = (int) ((Math.abs(Math.log((value1 + alpha) / (value2 + alpha)))) * 255);
            result.setPixel(x, y, Color.rgb(resultValue, resultValue, resultValue));
        }//ww w . jav  a2 s .c o  m
    //        grayBitmap1.recycle();
    //        grayBitmap2.recycle();
    return result;
}

From source file:Main.java

/**
 * Convert time to a string//w  ww . ja  v a2s .co m
 *
 * @param millis e.g.time/length from file
 * @return Formatted string (hh:)mm:ss
 */
public static String millisToString(long millis) {
    boolean negative = millis < 0;
    millis = Math.abs(millis);

    millis /= 1000;
    int sec = (int) (millis % 60);
    millis /= 60;
    int min = (int) (millis % 60);
    millis /= 60;
    int hours = (int) millis;

    String time;
    DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
    format.applyPattern("00");
    if (millis > 0) {
        time = (negative ? "-" : "") + hours + ":" + format.format(min) + ":" + format.format(sec);
    } else {
        time = (negative ? "-" : "") + min + ":" + format.format(sec);
    }

    return time;
}

From source file:Main.java

public static double[] absarr(double[] a) {
    double[] absarr = new double[a.length];

    for (int i = 0; i < a.length; i++)
        absarr[i] = Math.abs(a[i]);

    return absarr;
}

From source file:com.opengamma.maths.lowlevelapi.functions.utilities.Abs.java

public static float[] stateless(float[] v) {
    Validate.notNull(v);/*  w w  w.  jav  a  2  s.  c  om*/
    final int n = v.length;
    float[] tmp = new float[n];
    for (int i = 0; i < n; i++) {
        tmp[i] = Math.abs(v[i]);
    }
    return tmp;
}

From source file:Main.java

public static List<Integer> toAbsIntegerList(final Collection<Integer> array) {
    final ArrayList<Integer> retValue = new ArrayList<Integer>();
    for (final Integer item : array)
        retValue.add(Math.abs(item));
    return retValue;
}

From source file:Main.java

public static void barrelDistortion(double paramA, double paramB, double paramC, PointF src) {

    double paramD = 1.0 - paramA - paramB - paramC; // describes the linear scaling of the image

    float d = 1.0f;

    // center of dst image
    double centerX = 0f;
    double centerY = 0f;

    if (src.x == centerX && src.y == centerY) {
        return;//www  .j av a 2s.c o  m
    }

    // cartesian coordinates of the destination point (relative to the centre of the image)
    double deltaX = (src.x - centerX) / d;
    double deltaY = (src.y - centerY) / d;

    // distance or radius of dst image
    double dstR = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

    // distance or radius of src image (with formula)
    double srcR = (paramA * dstR * dstR * dstR + paramB * dstR * dstR + paramC * dstR + paramD) * dstR;

    // comparing old and new distance to get factor
    double factor = Math.abs(dstR / srcR);

    // coordinates in source image
    float xResult = (float) (centerX + (deltaX * factor * d));
    float yResult = (float) (centerY + (deltaY * factor * d));

    src.set(xResult, yResult);
}

From source file:com.bootcamp.utils.IdGen.java

/**
 * SecureRandom??Long. 
 */
public static long randomLong() {
    return Math.abs(random.nextLong());
}

From source file:Main.java

public static void abs(double[] array) {
    for (int i = 0; i < array.length; i++)
        array[i] = Math.abs(array[i]);
}

From source file:Main.java

public static String formatDegToDms(double degrees, double min, double max) {
    String s = "";
    // normalize values within the given range
    double deg = normalizeAngle(degrees, min, max);
    // take sign into account
    if (deg < 0) {
        deg = Math.abs(deg);
        s += "-";
    }//  www .  ja v  a  2 s.  co  m
    double arcmin = (deg - (int) deg) * 60.0;
    double arcsec = (arcmin - (int) arcmin) * 60.0;
    s += new DecimalFormat("00").format((int) deg) + "d" + new DecimalFormat("00").format((int) arcmin) + "'"
            + new DecimalFormat("00.00").format(arcsec) + "\"";
    return s;
}

From source file:Main.java

private static AffineTransform createRandomTransform(double angleRad) {
    AffineTransform at = new AffineTransform();
    double scale = 1.0;
    at.translate(randomDouble(), randomDouble());
    scale = Math.abs(randomDouble());
    at.scale(scale, scale);/*from  w w w.j a v a  2s .  c  om*/
    at.rotate(angleRad);
    at.translate(randomDouble(), randomDouble());
    scale = Math.abs(randomDouble());
    at.scale(scale, scale);
    return at;
}