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:de.tud.kom.p2psim.impl.util.stats.ConfidenceInterval.java

/**
 * Returns the delta between the mean and the lower(x1)/upper(x2) bound as
 * positive number. That is, the probabilistic bounds of x1 and x2 are given
 * by x1 <= mean <= x2 <=> mean-delta <= mean <= mean + delta
 * /*from  w  w w .j  ava2 s .c o m*/
 * @param sdev
 *            the given standard deviation
 * @param n
 *            the given sample size
 * @param alpha
 *            the given significance level
 * @return the upper/lower bound as positiv number
 */
public static double getDeltaBound(double sdev, int n, double alpha) {
    TDistribution tDist = DistributionFactory.newInstance().createTDistribution(n - 1);
    double errorConfCoeff = 1d - (alpha / 2);
    double delta;
    try {
        double t = Math.abs(tDist.inverseCumulativeProbability(errorConfCoeff));
        delta = t * sdev / Math.sqrt(n);
    } catch (MathException e) {
        throw new IllegalStateException(e);
    }
    return delta;
}

From source file:Main.java

/**
 * Selects the optimal picture size with flags to toggle filtering criteria.
 *
 * @param previewSizes       the list of supported preview sizes.
 * @param pictureSizes       the list of supported picture sizes.
 * @param targetWidth        the target picture width.
 * @param targetHeight       the target picture height.
 * @param filterMinSize      true to block sizes smaller than target dimensions; false otherwise.
 * @param filterAspectRatio  true to block sizes above the aspect ratio tolerance; false otherwise.
 * @param filterPreviewSizes true to block sizes without a corresponding preview size; false otherwise.
 * @return the optimal supported picture size; or null if failed.
 *//* w w  w  .  j a v a2  s.  c  o  m*/
private static Size selectPictureSize(List<Size> previewSizes, List<Size> pictureSizes, final int targetWidth,
        final int targetHeight, boolean filterMinSize, boolean filterAspectRatio, boolean filterPreviewSizes) {
    Size optimalSize = null;

    double targetAspectRatio = (double) targetWidth / targetHeight;
    int minArea = Integer.MAX_VALUE;
    for (Size size : pictureSizes) {
        // Block sizes smaller than target dimensions.
        if (filterMinSize && (size.width < targetWidth || size.height < targetHeight)) {
            continue;
        }

        // Block sizes above the aspect ratio tolerance.
        double aspectRatio = (double) size.width / size.height;
        if (filterAspectRatio && (Math.abs(aspectRatio - targetAspectRatio) > PICTURE_ASPECT_RATIO_TOLERANCE)) {
            continue;
        }

        // Block sizes without a corresponding preview size.
        if (filterPreviewSizes && !previewSizes.contains(size)) {
            continue;
        }

        // Select smallest size.
        int area = size.width * size.height;
        if (area < minArea) {
            optimalSize = size;
            minArea = area;
        }
    }

    return optimalSize;
}

From source file:net.gtaun.shoebill.data.Velocity.java

public float angle2d() {
    return (float) Math.acos(getX() / Math.abs(speed2d()));
}

From source file:Main.java

/**
 * Iterate over supported camera video sizes to see which one best fits the
 * dimensions of the given view while maintaining the aspect ratio. If none can,
 * be lenient with the aspect ratio./*from ww w.  j  a  v  a  2s . c  om*/
 *
 * @param supportedVideoSizes Supported camera video sizes.
 * @param previewSizes Supported camera preview sizes.
 * @param w     The width of the view.
 * @param h     The height of the view.
 * @return Best match camera video size to fit in the view.
 */
public static Camera.Size getOptimalVideoSize(List<Camera.Size> supportedVideoSizes,
        List<Camera.Size> previewSizes, int w, int h) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.1;
    double targetRatio = (double) w / h;

    // Supported video sizes list might be null, it means that we are allowed to use the preview
    // sizes
    List<Camera.Size> videoSizes;
    if (supportedVideoSizes != null) {
        videoSizes = supportedVideoSizes;
    } else {
        videoSizes = previewSizes;
    }
    Camera.Size optimalSize = null;

    // Start with max value and refine as we iterate over available video sizes. This is the
    // minimum difference between view and camera height.
    double minDiff = Double.MAX_VALUE;

    // Target view height
    int targetHeight = h;

    // Try to find a video size that matches aspect ratio and the target view size.
    // Iterate over all available sizes and pick the largest size that can fit in the view and
    // still maintain the aspect ratio.
    for (Camera.Size size : videoSizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find video size that matches the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : videoSizes) {
            if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:Main.java

/**
 * Iterate over supported camera video sizes to see which one best fits the
 * dimensions of the given view while maintaining the aspect ratio. If none can,
 * be lenient with the aspect ratio.//from w  w w  .ja v  a  2  s  .  c  o m
 *
 * @param supportedVideoSizes Supported camera video sizes.
 * @param previewSizes Supported camera preview sizes.
 * @param w     The width of the view.
 * @param h     The height of the view.
 * @return Best match camera video size to fit in the view.
 */
public static Camera.Size getOptimalVideoSize(List<Camera.Size> supportedVideoSizes,
        List<Camera.Size> previewSizes, int w, int h) {
    // Use a very small tolerance because we want an exact match.
    final double ASPECT_TOLERANCE = 0.1;
    double targetRatio = (double) w / h;

    // Supported video sizes list might be null, it means that we are allowed to use the preview
    // sizes
    List<Camera.Size> videoSizes;
    if (supportedVideoSizes != null) {
        videoSizes = supportedVideoSizes;
    } else {
        videoSizes = previewSizes;
    }
    Camera.Size optimalSize = null;

    // Start with max value and refine as we iterate over available video sizes. This is the
    // minimum difference between view and camera height.
    double minDiff = Double.MAX_VALUE;

    // Target view height
    int targetHeight = h;

    // Try to find a video size that matches aspect ratio and the target view size.
    // Iterate over all available sizes and pick the largest size that can fit in the view and
    // still maintain the aspect ratio.
    for (Camera.Size size : videoSizes) {
        double ratio = (double) size.height / size.width;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
            continue;
        if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find video size that matches the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Camera.Size size : videoSizes) {
            if (Math.abs(size.height - targetHeight) < minDiff && previewSizes.contains(size)) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}

From source file:conceptor.chaos.Lyapunov.java

private static boolean isUnbounded(double[] x) {
    double absSum = 0.0;
    for (int i = 0; i < x.length; i++) {
        absSum += Math.abs(x[i]);
    }/*from  w  w w . j a  v a  2  s.c o m*/
    if (absSum >= 10e6) {
        return true;
    } else {
        return false;
    }
}

From source file:com.springmvc.dao.TimeLogDAO.java

public void updateLogout(TimeLog timeLog) {
    TimeLog timeLogToUpdate = getTimeLog(timeLog.getId());

    Date date = new Date();
    Timestamp time = new Timestamp(date.getTime());
    timeLogToUpdate.setLogout(time);//  w  w w  .jav a 2 s.  c o m

    Timestamp login = timeLogToUpdate.getLogin();
    long diff = Math.abs(login.getTime() - time.getTime());

    long second = (diff / 1000) % 60;
    long minute = (diff / (1000 * 60)) % 60;
    long hour = (diff / (1000 * 60 * 60)) % 24;
    long day = (diff / (1000 * 60 * 60 * 24));
    String toString = String.format("%02dd:%02dh:%02dm:%02ds", day, hour, minute, second, diff);
    timeLogToUpdate.setDuration(toString);

    getCurrentSession().update(timeLogToUpdate);
}

From source file:ms.sujinkim.com.test.MjpegViewGestureDetector.java

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    boolean value = false;
    try {//w  w  w.  ja  va2s.com
        if (Math.abs(e1.getY() - e2.getY()) < FLING_MAX_OFF_PATH) {
            if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingLeft(e1.getX() - e2.getX());
            } else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
                    && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingRight(e2.getX() - e1.getX());
            }
            value = true;
        } else if (Math.abs(e1.getX() - e2.getX()) < FLING_MAX_OFF_PATH) {
            if (e1.getY() - e2.getY() > FLING_MIN_DISTANCE && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingUp(e1.getY() - e2.getY());
            } else if (e2.getY() - e1.getY() > FLING_MIN_DISTANCE
                    && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingDown(e2.getY() - e1.getY());
            }
            value = true;
        }
    } catch (Exception e) {
        /* Do nothing */
    }
    return value;
}

From source file:io.yields.math.concepts.operator.Volume.java

public double compute() {
    UnivariateFunction function = x -> Math.abs(lowerCurve.apply(x) - upperCurve.apply(x));
    return integrator.integrate(CurveLength.MAX_EVAL, function, min, max);
}

From source file:Main.java

/**
 * Convert RGB components to HSL (hue-saturation-lightness).
 * <ul>//from ww w  .  ja va  2s .c o m
 * <li>outHsl[0] is Hue [0 .. 360)</li>
 * <li>outHsl[1] is Saturation [0...1]</li>
 * <li>outHsl[2] is Lightness [0...1]</li>
 * </ul>
 *
 * @param r      red component value [0..255]
 * @param g      green component value [0..255]
 * @param b      blue component value [0..255]
 * @param outHsl 3-element array which holds the resulting HSL components
 */
public static void RGBToHSL(int r, int g, int b, float[] outHsl) {
    final float rf = r / 255f;
    final float gf = g / 255f;
    final float bf = b / 255f;

    final float max = Math.max(rf, Math.max(gf, bf));
    final float min = Math.min(rf, Math.min(gf, bf));
    final float deltaMaxMin = max - min;

    float h, s;
    float l = (max + min) / 2f;

    if (max == min) {
        // Monochromatic
        h = s = 0f;
    } else {
        if (max == rf) {
            h = ((gf - bf) / deltaMaxMin) % 6f;
        } else if (max == gf) {
            h = ((bf - rf) / deltaMaxMin) + 2f;
        } else {
            h = ((rf - gf) / deltaMaxMin) + 4f;
        }

        s = deltaMaxMin / (1f - Math.abs(2f * l - 1f));
    }

    h = (h * 60f) % 360f;
    if (h < 0) {
        h += 360f;
    }

    outHsl[0] = constrain(h, 0f, 360f);
    outHsl[1] = constrain(s, 0f, 1f);
    outHsl[2] = constrain(l, 0f, 1f);
}