Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

In this page you can find the example usage for java.math BigDecimal doubleValue.

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

From source file:com.chinamobile.bcbsp.ml.math.DenseDoubleVector.java

@Override
public double dotUnsafe(DoubleVector vector) {
    BigDecimal dotProduct = BigDecimal.valueOf(0.0d);
    for (int i = 0; i < getLength(); i++) {
        dotProduct = dotProduct//from   www  .  ja v  a  2s.  c  o  m
                .add(BigDecimal.valueOf(this.get(i)).multiply(BigDecimal.valueOf(vector.get(i))));
    }
    return dotProduct.doubleValue();
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MaxTest.java

/**
 * Tests well calculation.//from w w  w .java  2 s.  c om
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMax();

            BigDecimal returned = max.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MinTest.java

/**
 * Tests well calculation./*from ww  w.  j av  a  2  s  . com*/
 */
@Test
public void testWell() {

    for (Plate plate : array) {

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.MaxBigDecimalTest.java

/**
 * Tests well calculation./*from   w  w  w. j a va  2  s. co m*/
 */
@Test
public void testWell() {

    for (PlateBigDecimal plate : array) {

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMax();

            BigDecimal returned = max.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflex.stat.statbigdecimal.MinBigDecimalTest.java

/**
 * Tests well calculation./*from  ww  w. j  a  v a  2  s  .  co m*/
 */
@Test
public void testWell() {

    for (PlateBigDecimal plate : array) {

        for (WellBigDecimal well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMin();

            BigDecimal returned = min.well(well);
            BigDecimal result = new BigDecimal(resultDouble);

            BigDecimal[] corrected = correctRoundingErrors(returned, result);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:cpcc.core.base.PolygonZone.java

/**
 * @return the coordinates of the center of gravity.
 *//*  w w w . j  a  va  2 s  . c  om*/
public PolarCoordinate getCenterOfGravity() {
    BigDecimal x = new BigDecimal(0), y = new BigDecimal(0);
    BigDecimal doubleArea = new BigDecimal(0);

    for (int k = 0, l = vertices.length - 1; k < l; ++k) {
        BigDecimal ax = new BigDecimal(vertices[k].x);
        BigDecimal ay = new BigDecimal(vertices[k].y);
        BigDecimal bx = new BigDecimal(vertices[k + 1].x);
        BigDecimal by = new BigDecimal(vertices[k + 1].y);
        BigDecimal t = ax.multiply(by).subtract(bx.multiply(ay));
        x = x.add(ax.add(bx).multiply(t));
        y = y.add(ay.add(by).multiply(t));
        doubleArea = doubleArea.add(ax.multiply(by).subtract(bx.multiply(ay)));
    }

    double sixTimesArea = 3.0 * doubleArea.doubleValue();
    return new PolarCoordinate(x.doubleValue() / sixTimesArea, y.doubleValue() / sixTimesArea, 0);
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MaxTest.java

/**
 * Tests the plate statistics method.//from w w w .ja va2 s . co  m
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = max.plate(plate);

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMax();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MinTest.java

/**
 * Tests the plate statistics method./*  ww  w.  j  a va2 s .  c  om*/
 */
@Test
public void testPlate() {

    for (Plate plate : array) {

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = min.plate(plate);

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMin();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }
}

From source file:com.modusoperandi.dragonfly.widgets.map.MapWidgetBMPage.java

@SuppressWarnings("unchecked")
private void generateMarkerJs(final SearchResponse results, final StringBuffer markerJs,
        final String locationField) {

    for (final SearchHit hit : results.getHits().getHits()) {

        final GeoPoint location = new GeoPoint();
        location.resetFromString(hit.getSource().get(locationField).toString());

        final BigDecimal lat = new BigDecimal(location.lat()).setScale(11, BigDecimal.ROUND_HALF_DOWN);
        final BigDecimal lon = new BigDecimal(location.lon()).setScale(11, BigDecimal.ROUND_HALF_DOWN);

        markerJs.append("markerLayer.addLayer(L.marker([");
        markerJs.append(Double.toString(lat.doubleValue()));
        markerJs.append(",");
        markerJs.append(Double.toString(lon.doubleValue()));

        final StringBuffer markerText = new StringBuffer();
        hit.getSource().entrySet().stream().forEach((fields) -> {
            String markerValue = (String) fields.getValue();

            try {
                markerText.append("<b>");
                markerText.append(fields.getKey());
                markerText.append(" :</b> ");

                if (isLink(fields.getKey(), ((Map<String, Object>) typeMappings.get(hit.getType())
                        .getSourceAsMap().get("_meta")))) {

                    markerText.append("<a href=\"");
                    markerText.append(markerValue);
                    markerText.append("\">");
                    markerText.append(markerValue);
                    markerText.append("</a>");

                } else {
                    if (markerValue.length() > MAX_POPUP_ROW_LENGTH) {
                        markerValue = markerValue.substring(0, MAX_POPUP_ROW_LENGTH) + " ...";
                    }//w w  w.ja  v  a2 s.  co m
                    markerText.append(StringEscapeUtils.escapeHtml(markerValue).replace('\n', ' '));
                }
                markerText.append("<br>");

            } catch (final IOException e) {
                LOGGER.log(Level.SEVERE, "Cannot access type mappings", e);
            } catch (final Exception e2) {
                LOGGER.log(Level.SEVERE, e2.getMessage(), e2);
            }
        });

        markerJs.append("]).bindPopup('");
        markerJs.append(markerText.toString().replace("'", " "));
        markerJs.append("', {maxWidth: 500}));\n");
    }
}

From source file:com.github.jessemull.microflexbigdecimal.stat.MaxTest.java

/**
 * Tests set calculation./*from  w  w  w  .  ja va  2 s.  com*/
 */
@Test
public void testSet() {

    for (Plate plate : array) {

        Map<Well, BigDecimal> resultMap = new TreeMap<Well, BigDecimal>();
        Map<Well, BigDecimal> returnedMap = max.set(plate.dataSet());

        for (Well well : plate) {

            double[] input = new double[well.size()];
            int index = 0;

            for (BigDecimal bd : well) {
                input[index++] = bd.doubleValue();
            }

            DescriptiveStatistics stat = new DescriptiveStatistics(input);
            double resultDouble = stat.getMax();

            BigDecimal result = new BigDecimal(resultDouble);

            resultMap.put(well, result);
        }

        for (Well well : plate) {

            BigDecimal result = resultMap.get(well);
            BigDecimal returned = returnedMap.get(well);

            BigDecimal[] corrected = correctRoundingErrors(result, returned);

            assertEquals(corrected[0], corrected[1]);
        }
    }

}