Example usage for java.lang Math round

List of usage examples for java.lang Math round

Introduction

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

Prototype

public static long round(double a) 

Source Link

Document

Returns the closest long to the argument, with ties rounding to positive infinity.

Usage

From source file:geogebra.kernel.statistics.AlgoHyperGeometric.java

protected final void compute() {

    if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined()) {
        int param = (int) Math.round(a.getDouble());
        int param2 = (int) Math.round(b.getDouble());
        int param3 = (int) Math.round(c.getDouble());
        double val = d.getDouble();
        try {/*from  ww w .java  2s. c  o m*/
            HypergeometricDistribution dist = getHypergeometricDistribution(param, param2, param3);
            if (isCumulative.getBoolean())
                num.setValue(dist.cumulativeProbability(val)); // P(X <= val)
            else
                num.setValue(dist.probability(val)); // P(X = val)

        } catch (Exception e) {
            num.setUndefined();
        }
    } else
        num.setUndefined();
}

From source file:cc.recommenders.evaluation.data.BoxplotDataTest.java

private void initSortedSut() {
    sut = new BoxplotData();
    long numValues = Math.round(1 / TEST_PRECISION);
    for (int i = 1; i <= numValues; i++) {
        sut.add(i * TEST_PRECISION);/*ww  w . ja  v  a 2  s. co m*/
    }
}

From source file:Main.java

/**
 *  Convert HSL values to a RGB Color./*from  w w w .  j  a v  a2  s  . co m*/
 *
 *  @param h Hue is specified as degrees in the range 0 - 360.
 *  @param s Saturation is specified as a percentage in the range 1 - 100.
 *  @param l Lumanance is specified as a percentage in the range 1 - 100.
 *  @paran alpha  the alpha value between 0 - 1
 *  adapted from https://svn.codehaus.org/griffon/builders/gfxbuilder/tags/GFXBUILDER_0.2/
 *  gfxbuilder-core/src/main/com/camick/awt/HSLColor.java
 */
@SuppressWarnings("PMD.MethodNamingConventions")
public static int[] HSLtoRGB(float h, float s, float l, float alpha) {
    if (s < 0.0f || s > 100.0f) {
        String message = "Color parameter outside of expected range - Saturation";
        throw new IllegalArgumentException(message);
    }

    if (l < 0.0f || l > 100.0f) {
        String message = "Color parameter outside of expected range - Luminance";
        throw new IllegalArgumentException(message);
    }

    if (alpha < 0.0f || alpha > 1.0f) {
        String message = "Color parameter outside of expected range - Alpha";
        throw new IllegalArgumentException(message);
    }

    //  Formula needs all values between 0 - 1.

    h = h % 360.0f;
    h /= 360f;
    s /= 100f;
    l /= 100f;

    float q = 0;

    if (l < 0.5) {
        q = l * (1 + s);
    } else {
        q = (l + s) - (s * l);
    }

    float p = 2 * l - q;

    int r = Math.round(Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)) * 256));
    int g = Math.round(Math.max(0, HueToRGB(p, q, h) * 256));
    int b = Math.round(Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)) * 256));

    return new int[] { r, g, b };
}

From source file:jprobix.ui.SPlotFinal.java

private static XYDataset samplexydataset2() {
    int cols = 20;
    int rows = 20;
    double[][] values = new double[cols][rows];

    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    XYSeries series = new XYSeries("Random");

    Random rand = new Random();
    for (int i = 0; i < values.length; i++) {
        for (int j = 0; j < values.length; j++) {
            double x = Math.round(rand.nextDouble() * 500);
            double y = Math.round(rand.nextDouble() * 500);

            series.add(x, y);/*from w w w.  j a v a 2  s.c  o m*/
        }
    }
    xySeriesCollection.addSeries(series);
    return xySeriesCollection;

}

From source file:br.com.everson.clei.springmvc.controller.ClienteController.java

@RequestMapping("/salvarCadastroDeCliente")
public String persistirNovoCliente(Model m, Cliente c) {
    c.setId(Math.round(Math.random() * 10000));
    try {//from   w ww.  j  av  a  2  s  .com
        begin();
        getSession().save(c);
        commit();
    } catch (HibernateException e) {
        rollback();
        e.printStackTrace();
    }
    clientes.add(c);
    return "redirect:inicio";
}

From source file:com.hortonworks.pso.data.generator.fields.BooleanField.java

public String getValue() {
    return booleanValues[(int) Math.round(random.nextFloat())];
}

From source file:Main.java

public static Bitmap decodeFile(File theFile, int IMAGE_MAX_SIZE) {
    Bitmap bmp = null;/*from ww  w  .j  a v  a 2 s  . c  om*/
    try {
        // Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;

        FileInputStream fis = new FileInputStream(theFile);
        BitmapFactory.decodeStream(fis, null, o);
        fis.close();

        int scale = 1;
        if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
            scale = (int) Math.pow(2, (int) Math.round(
                    Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
        }

        // Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize = scale;
        fis = new FileInputStream(theFile);
        bmp = BitmapFactory.decodeStream(fis, null, o2);

        fis.close();
    } catch (IOException e) {
    }
    return bmp;
}

From source file:geogebra.kernel.statistics.AlgoBinomialDist.java

@SuppressWarnings("deprecation")
protected final void compute() {

    if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined() && input[3].isDefined()) {
        int param = (int) Math.round(a.getDouble());
        double param2 = b.getDouble();
        double val = c.getDouble();
        try {//  w ww.  j a v  a 2s. co m
            BinomialDistribution dist = getBinomialDistribution(param, param2);
            if (isCumulative.getBoolean())
                num.setValue(dist.cumulativeProbability(val)); // P(X <= val)
            else
                num.setValue(dist.probability(val)); // P(X = val)
        } catch (Exception e) {
            Application.debug(e.getMessage());
            num.setUndefined();
        }
    } else
        num.setUndefined();
}

From source file:com.maskyn.fileeditorpro.util.AccessStorageApi.java

public static Bitmap loadPrescaledBitmap(String filename) throws IOException {
    // Facebook image size
    final int IMAGE_MAX_SIZE = 630;

    File file = null;//  w  w  w. ja  v  a  2s.  c  om
    FileInputStream fis;

    BitmapFactory.Options opts;
    int resizeScale;
    Bitmap bmp;

    file = new File(filename);

    // This bit determines only the width/height of the bitmap without loading the contents
    opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;
    fis = new FileInputStream(file);
    BitmapFactory.decodeStream(fis, null, opts);
    fis.close();

    // Find the correct scale value. It should be a power of 2
    resizeScale = 1;

    if (opts.outHeight > IMAGE_MAX_SIZE || opts.outWidth > IMAGE_MAX_SIZE) {
        resizeScale = (int) Math.pow(2, (int) Math.round(
                Math.log(IMAGE_MAX_SIZE / (double) Math.max(opts.outHeight, opts.outWidth)) / Math.log(0.5)));
    }

    // Load pre-scaled bitmap
    opts = new BitmapFactory.Options();
    opts.inSampleSize = resizeScale;
    fis = new FileInputStream(file);
    bmp = BitmapFactory.decodeStream(fis, null, opts);

    fis.close();

    return bmp;
}