Example usage for java.lang Math log10

List of usage examples for java.lang Math log10

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double log10(double a) 

Source Link

Document

Returns the base 10 logarithm of a double value.

Usage

From source file:us.mn.state.health.lims.reports.action.implementation.PatientReport.java

private String getAugmentedResult(ClinicalPatientData data, Result result) {
    String resultValue = data.getResult();
    if (TestIdentityService.isTestNumericViralLoad(reportAnalysis.getTest())) {
        try {/*from   www  .  ja v  a2s  .  c  om*/
            resultValue += " (" + twoDecimalFormat.format(Math.log10(Double.parseDouble(resultValue)))
                    + ")log ";
        } catch (IllegalFormatException e) {
            // no-op
        }
    }

    return resultValue + (augmentResultWithFlag() ? getResultFlag(result, null) : "");
}

From source file:org.gumtree.vis.plot1d.KLogarithmicAxis.java

private int getFirstDigit(double value) {
    double log = Math.log10(value);
    double base = Math.floor(log);
    return (int) (value / Math.pow(10, base));
}

From source file:at.alladin.rmbt.statisticServer.OpenTestSearchResource.java

/**
 * Gets the JSON Array for a specific histogram
 * @param min lower bound of first class
 * @param max upper bound of last class/*w w w .  j  ava 2 s .  c  o m*/
 * @param field numeric database-field that the histogram is based on 
 * @param isLogarithmic
 * @param whereClause
 * @param searchValues
 * @return
 * @throws JSONException 
 * @throws CacheException 
 */
private JSONArray getJSONForHistogram(double min, double max, String field, boolean isLogarithmic,
        String whereClause, Queue<Map.Entry<String, FieldType>> searchValues) throws JSONException {

    //Get min and max steps
    double difference = max - min;
    int digits = (int) Math.floor(Math.log10(difference));

    //get histogram classes
    long upperBound = new BigDecimal(max).setScale(-digits, BigDecimal.ROUND_CEILING).longValue();
    long lowerBound = new BigDecimal(min).setScale(-digits, BigDecimal.ROUND_FLOOR).longValue();
    double step = ((double) (upperBound - lowerBound)) / ((double) HISTOGRAMCLASSES);

    System.out.println("lower: " + lowerBound + ", upper: " + upperBound + ", digits: " + digits + ", diff: "
            + difference + ", step: " + step);

    //psql width_bucket: gets the histogram class in which a value belongs
    final String sql = "select " + " width_bucket(" + field + "," + lowerBound + "," + upperBound + ","
            + HISTOGRAMCLASSES + ") bucket, " + " count(*) cnt " + " from test t "
            + " LEFT JOIN network_type nt ON nt.uid=t.network_type"
            + " LEFT JOIN device_map adm ON adm.codename=t.model"
            + " LEFT JOIN test_server ts ON ts.uid=t.server_id"
            + " LEFT JOIN provider prov ON provider_id = prov.uid "
            + " LEFT JOIN provider mprov ON mobile_provider_id = mprov.uid" + " where " + field + " > 0 "
            + " AND t.deleted = false" + ((this.excludeImplausible) ? " AND implausible = false" : "")
            + " AND status = 'FINISHED' " + whereClause + " group by bucket " + "order by bucket asc;";

    JSONArray jArray = new JSONArray();
    try {
        PreparedStatement stmt = conn.prepareStatement(sql);
        stmt = fillInWhereClause(stmt, searchValues, 1);
        ResultSet rs = stmt.executeQuery();

        JSONObject jBucket = null;
        long prevCnt = 0;
        int prevBucket = 0;
        while (rs.next()) {
            int bucket = rs.getInt("bucket");
            long cnt = rs.getLong("cnt");

            double current_lower_bound = lowerBound + step * (bucket - 1);
            //logarithmic -> times 10 for kbit
            if (isLogarithmic)
                current_lower_bound = Math.pow(10, current_lower_bound * 4) * 10;
            double current_upper_bound = lowerBound + (step * bucket);
            if (isLogarithmic)
                current_upper_bound = Math.pow(10, current_upper_bound * 4) * 10;

            if (bucket - prevBucket > 1) {
                //problem: bucket without values
                //solution: respond with classes with "0" elements in them
                int diff = bucket - prevBucket;
                for (int i = 1; i < diff; i++) {
                    prevBucket++;
                    jBucket = new JSONObject();
                    double tLowerBound = lowerBound + step * (prevBucket - 1);
                    if (isLogarithmic)
                        tLowerBound = Math.pow(10, tLowerBound * 4) * 10;
                    double tUpperBound = lowerBound + (step * prevBucket);
                    if (isLogarithmic)
                        tUpperBound = Math.pow(10, tUpperBound * 4) * 10;
                    jBucket.put("lower_bound", tLowerBound);
                    jBucket.put("upper_bound", tUpperBound);
                    jBucket.put("results", 0);
                    jArray.put(jBucket);
                }
            }
            prevBucket = bucket;
            prevCnt = cnt;
            jBucket = new JSONObject();
            if (bucket == 0) {
                jBucket.put("lower_bound", JSONObject.NULL);
            } else {
                //2 digits accuracy for small differences
                if (step < 1 && !isLogarithmic)
                    jBucket.put("lower_bound", ((double) Math.round(current_lower_bound * 100)) / (double) 100);
                else
                    jBucket.put("lower_bound", Math.round(current_lower_bound));
            }

            if (bucket == HISTOGRAMCLASSES + 1) {
                jBucket.put("upper_bound", JSONObject.NULL);
            } else {
                if (step < 1 && !isLogarithmic)
                    jBucket.put("upper_bound", ((double) Math.round(current_upper_bound * 100)) / (double) 100);
                else
                    jBucket.put("upper_bound", Math.round(current_upper_bound));
            }
            jBucket.put("results", cnt);

            jArray.put(jBucket);
        }

        //problem: not enough buckets
        //solution: respond with classes with "0" elements
        if (jArray.length() < HISTOGRAMCLASSES) {
            int diff = HISTOGRAMCLASSES - jArray.length();
            int bucket = jArray.length();
            for (int i = 0; i < diff; i++) {
                jBucket = new JSONObject();
                bucket++;
                double tLowerBound = lowerBound + step * (bucket - 1);
                if (isLogarithmic)
                    tLowerBound = Math.pow(10, tLowerBound * 4) * 10;
                double tUpperBound = lowerBound + (step * bucket);
                if (isLogarithmic)
                    tUpperBound = Math.pow(10, tUpperBound * 4) * 10;
                jBucket.put("lower_bound", tLowerBound);
                jBucket.put("upper_bound", tUpperBound);
                jBucket.put("results", 0);
                jArray.put(jBucket);
            }
        }

        rs.close();
        stmt.close();

    } catch (SQLException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return jArray;
}

From source file:org.nd4j.linalg.util.BigDecimalMath.java

/**
 * The natural logarithm.//from  w  w  w.  j  a v a 2  s . c  o m
 *
 * @param n  The main argument, a strictly positive integer.
 * @param mc The requirements on the precision.
 * @return ln(n).
 */
static public BigDecimal log(int n, final MathContext mc) {
    /* the value is undefined if x is negative.
     */
    if (n <= 0) {
        throw new ArithmeticException("Cannot take log of negative " + n);
    } else if (n == 1) {
        return BigDecimal.ZERO;
    } else if (n == 2) {
        if (mc.getPrecision() < LOG2.precision()) {
            return LOG2.round(mc);
        } else {
            /* Broadhurst \protect\vrule width0pt\protect\href{http://arxiv.org/abs/math/9803067}{arXiv:math/9803067}
             * Error propagation: the error in log(2) is twice the error in S(2,-5,...).
             */
            int[] a = { 2, -5, -2, -7, -2, -5, 2, -3 };
            BigDecimal S = broadhurstBBP(2, 1, a, new MathContext(1 + mc.getPrecision()));
            S = S.multiply(new BigDecimal(8));
            S = sqrt(divideRound(S, 3));
            return S.round(mc);
        }
    } else if (n == 3) {
        /* summation of a series roughly proportional to (7/500)^k. Estimate count
         * of terms to estimate the precision (drop the favorable additional
         * 1/k here): 0.013^k <= 10^(-precision), so k*log10(0.013) <= -precision
         * so k>= precision/1.87.
         */
        int kmax = (int) (mc.getPrecision() / 1.87);
        MathContext mcloc = new MathContext(mc.getPrecision() + 1 + (int) (Math.log10(kmax * 0.693 / 1.098)));
        BigDecimal log3 = multiplyRound(log(2, mcloc), 19);
        /* log3 is roughly 1, so absolute and relative error are the same. The
         * result will be divided by 12, so a conservative error is the one
         * already found in mc
         */
        double eps = prec2err(1.098, mc.getPrecision()) / kmax;
        Rational r = new Rational(7153, 524288);
        Rational pk = new Rational(7153, 524288);
        for (int k = 1;; k++) {
            Rational tmp = pk.divide(k);
            if (tmp.doubleValue() < eps) {
                break;
            }
            /* how many digits of tmp do we need in the sum?
             */
            mcloc = new MathContext(err2prec(tmp.doubleValue(), eps));
            BigDecimal c = pk.divide(k).BigDecimalValue(mcloc);
            if (k % 2 != 0) {
                log3 = log3.add(c);
            } else {
                log3 = log3.subtract(c);
            }
            pk = pk.multiply(r);
        }
        log3 = divideRound(log3, 12);
        return log3.round(mc);
    } else if (n == 5) {
        /* summation of a series roughly proportional to (7/160)^k. Estimate count
         * of terms to estimate the precision (drop the favorable additional
         * 1/k here): 0.046^k <= 10^(-precision), so k*log10(0.046) <= -precision
         * so k>= precision/1.33.
         */
        int kmax = (int) (mc.getPrecision() / 1.33);
        MathContext mcloc = new MathContext(mc.getPrecision() + 1 + (int) (Math.log10(kmax * 0.693 / 1.609)));
        BigDecimal log5 = multiplyRound(log(2, mcloc), 14);
        /* log5 is roughly 1.6, so absolute and relative error are the same. The
         * result will be divided by 6, so a conservative error is the one
         * already found in mc
         */
        double eps = prec2err(1.6, mc.getPrecision()) / kmax;
        Rational r = new Rational(759, 16384);
        Rational pk = new Rational(759, 16384);
        for (int k = 1;; k++) {
            Rational tmp = pk.divide(k);
            if (tmp.doubleValue() < eps) {
                break;
            }
            /* how many digits of tmp do we need in the sum?
             */
            mcloc = new MathContext(err2prec(tmp.doubleValue(), eps));
            BigDecimal c = pk.divide(k).BigDecimalValue(mcloc);
            log5 = log5.subtract(c);
            pk = pk.multiply(r);
        }
        log5 = divideRound(log5, 6);
        return log5.round(mc);
    } else if (n == 7) {
        /* summation of a series roughly proportional to (1/8)^k. Estimate count
         * of terms to estimate the precision (drop the favorable additional
         * 1/k here): 0.125^k <= 10^(-precision), so k*log10(0.125) <= -precision
         * so k>= precision/0.903.
         */
        int kmax = (int) (mc.getPrecision() / 0.903);
        MathContext mcloc = new MathContext(
                mc.getPrecision() + 1 + (int) (Math.log10(kmax * 3 * 0.693 / 1.098)));
        BigDecimal log7 = multiplyRound(log(2, mcloc), 3);
        /* log7 is roughly 1.9, so absolute and relative error are the same.
         */
        double eps = prec2err(1.9, mc.getPrecision()) / kmax;
        Rational r = new Rational(1, 8);
        Rational pk = new Rational(1, 8);
        for (int k = 1;; k++) {
            Rational tmp = pk.divide(k);
            if (tmp.doubleValue() < eps) {
                break;
            }
            /* how many digits of tmp do we need in the sum?
             */
            mcloc = new MathContext(err2prec(tmp.doubleValue(), eps));
            BigDecimal c = pk.divide(k).BigDecimalValue(mcloc);
            log7 = log7.subtract(c);
            pk = pk.multiply(r);
        }
        return log7.round(mc);
    } else {
        /* At this point one could either forward to the log(BigDecimal) signature (implemented)
         * or decompose n into Ifactors and use an implemenation of all the prime bases.
         * Estimate of the result; convert the mc argument to an absolute error eps
         * log(n+errn) = log(n)+errn/n = log(n)+eps
         */
        double res = Math.log((double) n);
        double eps = prec2err(res, mc.getPrecision());
        /* errn = eps*n, convert absolute error in result to requirement on absolute error in input
         */
        eps *= n;

        /* Convert this absolute requirement of error in n to a relative error in n
         */
        final MathContext mcloc = new MathContext(1 + err2prec((double) n, eps));
        /* Padd n with a number of zeros to trigger the required accuracy in
         * the standard signature method
         */
        BigDecimal nb = scalePrec(new BigDecimal(n), mcloc);
        return log(nb);
    }
}

From source file:odcplot.OdcPlot.java

/**
 * Fill out the result image with the plot, bit names, time axis and legend
 * @throws IOException - must be a problem writing out the result file
 *///  w ww . j  av a  2  s .co m
private void finalizeImage() throws IOException {
    img.setData(rast); // copy the image raster
    addColorLegend();

    // add the bit names
    int bheight = dimY / nbits; // # of pixels high for each bit
    int lasc = labelMetrics.getAscent();
    int imgXmax = imgX0 + dimX;
    for (int b = 0; b < bitNames.length; b++) {
        String bname = bitNames[b];
        bname = bname.isEmpty() ? "Unused" : bname;
        int bw = labelMetrics.stringWidth(bname);
        int bx = imgX0 - 2 - bw;
        int by = bheight * b + (lasc + bheight) / 2 + imgY0;
        grph.drawString(bname, bx, by);
        int y = bheight * b + imgY0;
        grph.drawLine(1, y, imgXmax, y);
    }
    int y = bitNames.length * bheight + imgY0;
    grph.drawLine(1, y, imgXmax, y);
    grph.drawLine(1, imgY0, 1, y);

    // time axis labels, ticks & grid
    int tw = dimX / xTicks;
    float dt = duration / ((float) xTicks);
    String fmt = "%1$.0f";
    if (duration < xTicks) {
        fmt = "%1$.2f";
    } else if (duration < xTicks * 2) {
        fmt = "%1$.1f";
    }
    int yp = y + 5 + lasc;
    int lstGpsEnd = 0;

    for (int t = 0; t <= xTicks; t++) {
        int x = t * tw + imgX0;
        long tsec = Math.round(t * dt);
        String xLbl;
        if (duration > 5) {
            xLbl = TimeAndDate.hrTime(tsec);
        } else {
            xLbl = String.format("%1$.2f", t * dt);
        }
        int xw = labelMetrics.stringWidth(xLbl);
        int xp = x - xw / 2;
        if (t == xTicks) { // make sure the last tick is at the edge (round off errors)
                           // and the label ends there since we can't center it
            x = imgXmax;
            xp = x - xw;
        }
        grph.drawLine(x, imgY0, x, y + 3);
        grph.drawString(xLbl, xp, yp);

        // add gps time on every other tick

        if (t % 2 == 0 && addGPS) {
            String gpsLbl = String.format("%1$,d", startGPS + tsec);
            int gpsLblLen = labelMetrics.stringWidth(gpsLbl);
            if (t == xTicks) {
                xp = x - gpsLblLen;
            } else {
                xp = x - gpsLblLen / 2;
            }
            if (xp > lstGpsEnd + 5) {
                grph.drawString(gpsLbl, xp, yp + lblHeight + 3);
                lstGpsEnd = xp + gpsLblLen;
            }
        }
    }
    // aux info
    yp += lblHeight * 7 / 3;
    int imgCenter = (imgXmax - imgX0) / 2;
    int nsamples = (int) (duration * sampleRate);
    float spp = ((float) duration) / dimX;
    String auxInfo = String.format("Fs=%,.0fHz, n=%,d, ", sampleRate, nsamples);
    int lspp = (int) Math.round(Math.log10(spp));
    int nd = lspp < 0 ? (-lspp + 1) : lspp < 1 ? 2 : 1;
    String sfmt = String.format("pixel=%%.%df sec", nd);
    auxInfo += String.format(sfmt, spp);

    int xw = labelMetrics.stringWidth(auxInfo);
    int xp = imgCenter - xw / 2 + imgX0;

    grph.drawString(auxInfo, xp, yp);

    // draw some edge markers
    grph.drawLine(0, 0, 0, 5);
    grph.drawLine(0, 0, 5, 0);

    grph.drawLine(outX - 1, outY - 1, outX - 1, outY - 6);
    grph.drawLine(outX - 1, outY - 1, outX - 6, outY - 1);

    // write the file
    File outputfile = new File(ofileName);
    ImageIO.write(img, "png", outputfile);
    System.out.println("Wrote output to: " + ofileName);
}

From source file:org.broadinstitute.gatk.utils.MathUtils.java

/**
 * Computes a multinomial probability efficiently avoiding overflow even for large numbers.
 * This is computed using the formula://from   w  w w  .j  a  va2s  .co m
 * <p/>
 * M(x1,x2,...,xk; n; p1,p2,...,pk) = [ n! / (x1! x2! ... xk!) ] (p1^x1)(p2^x2)(...)(pk^xk)
 * <p/>
 * where xi represents the number of times outcome i was observed, n is the number of total observations, and
 * pi represents the probability of the i-th outcome to occur.  In this implementation, the value of n is
 * inferred as the sum over i of xi.
 *
 * @param k an int[] of counts, where each element represents the number of times a certain outcome was observed
 * @param p a double[] of probabilities, where each element represents the probability a given outcome can occur
 * @return the multinomial probability of the specified configuration.
 */
public static double multinomialProbability(final int[] k, final double[] p) {
    if (p.length != k.length)
        throw new IllegalArgumentException(
                "p and k: Array of log10 probabilities must have the same size as the array of number of sucesses: "
                        + p.length + ", " + k.length);

    int n = 0;
    double[] log10P = new double[p.length];
    for (int i = 0; i < p.length; i++) {
        log10P[i] = Math.log10(p[i]);
        n += k[i];
    }
    return Math.pow(10, log10MultinomialProbability(n, k, log10P));
}

From source file:org.multibit.utils.CSMiscUtils.java

public static int getNumberOfDisplayDecimalPlaces(CSAsset asset) {
    if (asset == null)
        return 0;
    double d = asset.getMultiple();
    if (d == 0.0)
        return 0;
    d = Math.log10(d);
    d = -d; // negate
    if (d < 0.0) {
        d = Math.floor(d);// w w  w  .  j  a v  a  2s .  c o  m
    } else if (d > 0.0) {
        d = Math.ceil(d);
    }
    int result = new Double(d).intValue();
    return result;
}

From source file:smlm.util.SRutil.java

public static double[] log10(double[] vector) {
    double[] retour = new double[vector.length];
    for (int i = 0; i < vector.length; i++) {
        retour[i] = Math.log10(vector[i]);
    }//from  w w  w .ja v  a  2  s . c  o  m
    return retour;
}

From source file:org.esa.nest.gpf.GCPSelectionOp.java

private void determiningImageOffset(final Band slaveBand1, final Band slaveBand2, int[] offset) {

    try {// ww w. j  a v  a  2s  .c o m
        // get master and slave imagettes
        final MetadataElement absRoot = AbstractMetadata.getAbstractedMetadata(sourceProduct);
        double groundRangeSpacing = absRoot.getAttributeDouble(AbstractMetadata.range_spacing, 1);
        final double azimuthSpacing = absRoot.getAttributeDouble(AbstractMetadata.azimuth_spacing, 1);
        final boolean srgrFlag = AbstractMetadata.getAttributeBoolean(absRoot, AbstractMetadata.srgr_flag);
        if (!srgrFlag) {
            final TiePointGrid incidenceAngle = OperatorUtils.getIncidenceAngle(sourceProduct);
            final double incidenceAngleAtCentreRangePixel = incidenceAngle.getPixelDouble(sourceImageWidth / 2f,
                    sourceImageHeight / 2f);
            groundRangeSpacing /= FastMath.sin(incidenceAngleAtCentreRangePixel * Constants.DTOR);
        }
        final int nRgLooks = Math.max(1, sourceImageWidth / 2048);
        final int nAzLooks = Math.max(1, (int) ((double) nRgLooks * groundRangeSpacing / azimuthSpacing + 0.5));
        final int targetImageWidth = sourceImageWidth / nRgLooks;
        final int targetImageHeight = sourceImageHeight / nAzLooks;
        final int windowWidth = (int) FastMath.pow(2, (int) (Math.log10(targetImageWidth) / Math.log10(2)));
        final int windowHeight = (int) FastMath.pow(2, (int) (Math.log10(targetImageHeight) / Math.log10(2)));
        final double[] mI = new double[windowWidth * windowHeight];
        final double[] sI = new double[windowWidth * windowHeight];

        final int tileCountX = 4;
        final int tileCountY = 4;
        final int tileWidth = windowWidth / tileCountX;
        final int tileHeight = windowHeight / tileCountY;
        final Rectangle[] tileRectangles = new Rectangle[tileCountX * tileCountY];
        int index = 0;
        for (int tileY = 0; tileY < tileCountY; tileY++) {
            final int ypos = tileY * tileHeight;
            for (int tileX = 0; tileX < tileCountX; tileX++) {
                final Rectangle tileRectangle = new Rectangle(tileX * tileWidth, ypos, tileWidth, tileHeight);
                tileRectangles[index++] = tileRectangle;
            }
        }

        final StatusProgressMonitor status = new StatusProgressMonitor(tileRectangles.length,
                "Computing offset... ");
        int tileCnt = 0;

        final ThreadManager threadManager = new ThreadManager();
        try {
            for (final Rectangle rectangle : tileRectangles) {
                checkForCancellation();

                final Thread worker = new Thread() {

                    @Override
                    public void run() {
                        final int x0 = rectangle.x;
                        final int y0 = rectangle.y;
                        final int w = rectangle.width;
                        final int h = rectangle.height;
                        final int xMax = x0 + w;
                        final int yMax = y0 + h;

                        final int xStart = x0 * nRgLooks;
                        final int yStart = y0 * nAzLooks;
                        final int xEnd = xMax * nRgLooks;
                        final int yEnd = yMax * nAzLooks;

                        final Rectangle srcRect = new Rectangle(xStart, yStart, xEnd - xStart, yEnd - yStart);
                        final Tile mstTile1 = getSourceTile(masterBand1, srcRect);
                        final ProductData mstData1 = mstTile1.getDataBuffer();
                        final TileIndex mstIndex = new TileIndex(mstTile1);
                        final Tile slvTile1 = getSourceTile(slaveBand1, srcRect);
                        final ProductData slvData1 = slvTile1.getDataBuffer();
                        final TileIndex slvIndex = new TileIndex(slvTile1);

                        ProductData mstData2 = null;
                        ProductData slvData2 = null;
                        if (complexCoregistration) {
                            mstData2 = getSourceTile(masterBand2, srcRect).getDataBuffer();
                            slvData2 = getSourceTile(slaveBand2, srcRect).getDataBuffer();
                        }

                        final double rgAzLooks = nRgLooks * nAzLooks;

                        for (int y = y0; y < yMax; y++) {
                            final int yByWidth = y * windowWidth;
                            final int y1 = y * nAzLooks;
                            final int y2 = y1 + nAzLooks;
                            for (int x = x0; x < xMax; x++) {
                                final int x1 = x * nRgLooks;
                                final int x2 = x1 + nRgLooks;
                                mI[yByWidth + x] = getMeanValue(x1, x2, y1, y2, mstData1, mstData2, mstIndex,
                                        rgAzLooks);
                                sI[yByWidth + x] = getMeanValue(x1, x2, y1, y2, slvData1, slvData2, slvIndex,
                                        rgAzLooks);
                            }
                        }

                        status.workedOne();
                    }
                };
                threadManager.add(worker);

                // status.worked(tileCnt++);
            }
            threadManager.finish();

        } catch (Throwable e) {
            OperatorUtils.catchOperatorException("GCPSelectionOp", e);
        } finally {
            status.done();
        }

        // correlate master and slave imagettes
        final RenderedImage masterImage = createRenderedImage(mI, windowWidth, windowHeight);
        final PlanarImage masterSpectrum = dft(masterImage);

        final RenderedImage slaveImage = createRenderedImage(sI, windowWidth, windowHeight);
        final PlanarImage slaveSpectrum = dft(slaveImage);
        final PlanarImage conjugateSlaveSpectrum = conjugate(slaveSpectrum);

        final PlanarImage crossSpectrum = multiplyComplex(masterSpectrum, conjugateSlaveSpectrum);
        final PlanarImage correlatedImage = idft(crossSpectrum);
        final PlanarImage crossCorrelatedImage = magnitude(correlatedImage);

        // compute offset
        final int w = crossCorrelatedImage.getWidth();
        final int h = crossCorrelatedImage.getHeight();
        final Raster idftData = crossCorrelatedImage.getData();
        final double[] real = idftData.getSamples(0, 0, w, h, 0, (double[]) null);

        int peakRow = 0;
        int peakCol = 0;
        double peak = 0;
        for (int r = 0; r < h; r++) {
            for (int c = 0; c < w; c++) {
                if (r >= h / 4 && r <= h * 3 / 4 || c >= w / 4 && c <= w * 3 / 4) {
                    continue;
                }
                final int s = r * w + c;
                if (peak < real[s]) {
                    peak = real[s];
                    peakRow = r;
                    peakCol = c;
                }
            }
        }

        // System.out.println("peakRow = " + peakRow + ", peakCol = " + peakCol);
        if (peakRow <= h / 2) {
            offset[1] = -peakRow * nAzLooks;
        } else {
            offset[1] = (h - peakRow) * nAzLooks;
        }

        if (peakCol <= w / 2) {
            offset[0] = -peakCol * nRgLooks;
        } else {
            offset[0] = (w - peakCol) * nRgLooks;
        }
        // System.out.println("offsetX = " + offset[0] + ", offsetY = " + offset[1]);

    } catch (Throwable e) {
        OperatorUtils.catchOperatorException(getId() + " getCoarseSlaveGCPPosition ", e);
    }
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL <code>LOG10(numeric)</code> operator applied to double values. */
public static double log10(double b0) {
    return Math.log10(b0);
}