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:com.bluelinelabs.conductor.demo.widget.ElasticDragDismissFrameLayout.java

private void dragScale(int scroll) {
    if (scroll == 0)
        return;//from  w w w. ja  va2  s  . co m

    totalDrag += scroll;

    // track the direction & set the pivot point for scaling
    // don't double track i.e. if start dragging down and then reverse, keep tracking as
    // dragging down until they reach the 'natural' position
    if (scroll < 0 && !draggingUp && !draggingDown) {
        draggingDown = true;
        if (shouldScale)
            setPivotY(getHeight());
    } else if (scroll > 0 && !draggingDown && !draggingUp) {
        draggingUp = true;
        if (shouldScale)
            setPivotY(0f);
    }

    setPivotX(getWidth() / 2);

    // how far have we dragged relative to the distance to perform a dismiss
    // (01 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit
    float dragFraction = (float) Math.log10(1 + (Math.abs(totalDrag) / dragDismissDistance));

    // calculate the desired translation given the drag fraction
    float dragTo = dragFraction * dragDismissDistance * dragElacticity;

    if (draggingUp) {
        // as we use the absolute magnitude when calculating the drag fraction, need to
        // re-apply the drag direction
        dragTo *= -1;
    }
    setTranslationY(dragTo);

    if (shouldScale) {
        final float scale = 1 - ((1 - dragDismissScale) * dragFraction);
        setScaleX(scale);
        setScaleY(scale);
    }

    // if we've reversed direction and gone past the settle point then clear the flags to
    // allow the list to get the scroll events & reset any transforms
    if ((draggingDown && totalDrag >= 0) || (draggingUp && totalDrag <= 0)) {
        totalDrag = dragTo = dragFraction = 0;
        draggingDown = draggingUp = false;
        setTranslationY(0f);
        setScaleX(1f);
        setScaleY(1f);
    }
    dispatchDragCallback(dragFraction, dragTo, Math.min(1f, Math.abs(totalDrag) / dragDismissDistance),
            totalDrag);
}

From source file:savant.util.MiscUtils.java

public static String posToShortStringWithSeparation(int pos, int separation) {

    if (separation > 10) {
        int backdigits = (int) Math.floor(Math.log10(separation));
        int significantDigits = 0;
        if (pos > 1000000000) {
            significantDigits = 9 - backdigits;
        } else if (pos > 1000000) {
            significantDigits = 6 - backdigits;
        } else if (pos > 1000) {
            significantDigits = 3 - backdigits;
        }/*  w  ww  .j  a va  2s . c om*/

        return posToShortString(pos, significantDigits);
    } else {
        // For separation of 10 or less, there's no point in using the G/M/k forms.
        return MiscUtils.numToString(pos);
    }
}

From source file:hulo.localization.models.obs.GaussianProcessLDPLMean.java

double ITUModel(double[] xr, double[] xs) {
    return -10.0 * params[0] * Math.log10(distance(xr, xs)) + params[1] - lossByFloorDiff(floorDiff(xr, xs));
}

From source file:com.linkedin.databus.core.TestTrailFilePositionSetter.java

private void createTrailFiles(String dir, String prefix, long numTxns, long numLinesPerFile,
        long numLinesPerNewline, String newlineChar, int startLine, Set<Long> corruptedScns, String corruption,
        boolean addAlternateCorruption, String altCorruption, String[] txnPattern, int numDbUpdatesWithSameScn,
        long currScn) throws IOException {
    long numFiles = ((numTxns * (txnPattern.length)) / numLinesPerFile) + 1;
    long numDigits = new Double(Math.log10(numFiles)).longValue() + 1;
    long currFileNum = 0;
    String currFile = prefix + toFixedLengthString(currFileNum, numDigits);
    long lineCount = 0;
    BufferedWriter w = createWriter(dir, currFile);
    int start = startLine;
    int dbUpdates = 0;
    for (long txn = 0; txn < numTxns; ++txn) {
        boolean corruptNextTokensEndTag = false;
        if (txn > 0)
            start = 0;/*from  w ww.j  ava  2 s.co m*/
        for (int j = 0; j < txnPattern.length; ++j) {
            lineCount++;
            String txnLine = txnPattern[j];
            if (txnLine.contains("${SCN}")) {
                dbUpdates++;
                txnLine = txnLine.replace("${SCN}",
                        new Long(currScn).toString() + (corruptedScns.contains(currScn) ? corruption : ""));
                if (addAlternateCorruption && corruptedScns.contains(currScn))
                    corruptNextTokensEndTag = true;
                if (dbUpdates >= numDbUpdatesWithSameScn) {
                    currScn++;
                    dbUpdates = 0;
                }
            }
            if (corruptNextTokensEndTag && txnLine.contains("</tokens>")) {
                //txnLine = txnLine.append(newlineChar).append("   ").append(altCorruption);
                txnLine = txnLine + newlineChar + "   " + altCorruption;
                corruptNextTokensEndTag = false;
            }

            if (j >= start) {
                w.append(txnLine);

                if (lineCount % numLinesPerNewline == 0)
                    w.append(newlineChar);
            }

            if ((lineCount % numLinesPerFile) == 0) {
                w.close();
                currFileNum++;
                currFile = prefix + toFixedLengthString(currFileNum, numDigits);
                w = createWriter(dir, currFile);
            }
        }
    }

    if (w != null)
        w.close();
}

From source file:interpolation.InteractiveRegression.java

protected static int computeScrollbarPositionValueFromDoubleExp(final int scrollbarMax, final double value,
        final double maxValue) {
    final int maxScrollHalf = scrollbarMax / 2;
    final double logMax = Math.log10(maxScrollHalf + 1);

    int scrollPos = (int) Math
            .round(maxScrollHalf + 1 - Math.pow(10, logMax - (Math.abs(value) / maxValue) * logMax));

    if (value < 0)
        scrollPos *= -1;//from ww  w.j  a  v  a 2s.  com

    return scrollPos + maxScrollHalf;
}

From source file:org.esa.nest.dat.views.polarview.Axis.java

private void setTickCount(int newTickCount) {
    tickCount = Math.abs(newTickCount);
    final double absMin = Math.abs(minValue);
    final double absMax = Math.abs(maxValue);
    final double largestValue = absMin <= absMax ? absMax : absMin;
    int exponent = (int) Math.floor(Math.log10(largestValue));
    if (Math.abs(exponent) < 5)
        exponent = 0;/*from www .  j  a  v a 2 s  .c  om*/
    double first = minValue;
    int lastTickIndex = tickCount - 1;
    double step = tickRange / (double) lastTickIndex;
    if (Math.abs((first + step) - minValue) < Math.abs(step * 0.15D)) {
        tickCount = lastTickIndex--;
        first += step;
        tickRange -= step;
    }
    if (Math.abs((first + tickRange) - maxValue) > Math.abs(step * 0.85D)) {
        tickCount = lastTickIndex--;
        tickRange -= step;
    }
    if (tickCount < 3) {
        lastTickIndex = 2;
        tickCount = 3;
        first = minValue;
        tickRange = axisRange;
        step = tickRange / (double) lastTickIndex;
    }
    if (tickValues == null || tickValues.length != tickCount) {
        tickValues = new double[tickCount];
        tickNames = new String[tickCount];
    }
    for (int i = 1; i < lastTickIndex; i++) {
        double v = first + (double) i * step;
        tickValues[i] = v;
        tickNames[i] = valueToString(v, exponent);
    }

    tickValues[0] = minValue;
    tickNames[0] = valueToString(minValue, exponent);
    tickValues[lastTickIndex] = maxValue;
    tickNames[lastTickIndex] = valueToString(maxValue, exponent);
    getTickPositions();
}

From source file:cpsControllers.ConversionController.java

/**
 * Szczytowy stosunek sygna - szum (PSNR, ang. <i>Peak Signal to Noise
 * Ratio</i>)//from   w w  w .j a v  a  2 s . c o  m
 *     
* @return
 */
public double obl_PSNR(ArrayList<Double> pynktyY, ArrayList<Double> _doPorownania) {
    double wynik = 0;
    try {
        if (!pynktyY.isEmpty() && !_doPorownania.isEmpty()) {
            double licznik = pynktyY.get(0), mianownik = 0;
            for (int i = 1; i < _doPorownania.size(); i++) {
                if (licznik < pynktyY.get(i)) {
                    licznik = pynktyY.get(i);
                }
            }
            mianownik = this.obl_MSE(pynktyY, _doPorownania);
            wynik = licznik / mianownik;
            wynik = 10.0D * Math.log10(wynik);
        } else {
            if (pynktyY.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Brak sygnau.", "Bd", JOptionPane.ERROR_MESSAGE);
            } else if (_doPorownania.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Brak zapisanej konwersji sygnau.", "Bd",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    } catch (Exception exc_MSE) {
        //            JOptionPane.showMessageDialog(null, "Nie mona obliczy:\n" + exc_MSE.getMessage(),
        //                    "Bd", JOptionPane.ERROR_MESSAGE);
    }

    System.out.println("PSNR = " + wynik);
    return wynik;
}

From source file:org.mklab.mikity.android.SettingsFragment.java

private void createAnimationSpeedComponent(final View mainView) {
    final EditText animationSpeedTextEdit = (EditText) mainView.findViewById(R.id.animationSpeedEditText);
    animationSpeedTextEdit.clearFocus();
    animationSpeedTextEdit.setText(String.format("%g", //$NON-NLS-1$
            Double.valueOf(SettingsFragment.this.canvasFragment.animationSpeedRate / 1000.0)));
    animationSpeedTextEdit.clearFocus();

    animationSpeedTextEdit.addTextChangedListener(new TextWatcher() {

        /**// w  ww  .  j av  a 2s  . co m
         * {@inheritDoc}
         */
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // nothing to do
        }

        /**
         * {@inheritDoc}
         */
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            //nothin to do
        }

        /**
         * {@inheritDoc}
         */
        public void afterTextChanged(Editable s) {
            final double value = Double.parseDouble(animationSpeedTextEdit.getText().toString());
            SettingsFragment.this.canvasFragment.animationSpeedRate = (int) Math.round(value * 1000);
        }
    });

    final ImageButton slowButton = (ImageButton) mainView.findViewById(R.id.slowButton);
    slowButton.setOnClickListener(new View.OnClickListener() {

        /**
         * {@inheritDoc}
         */
        public void onClick(View view) {
            int animationSpeedRate = SettingsFragment.this.canvasFragment.animationSpeedRate;

            final int step = (int) Math.floor(Math.log10(animationSpeedRate - 1));
            animationSpeedRate -= (int) Math.pow(10, step);
            if (animationSpeedRate < 0) {
                animationSpeedRate = 1;
            }
            animationSpeedTextEdit.setText(String.format("%g", Double.valueOf(animationSpeedRate / 1000.0))); //$NON-NLS-1$
            if (SettingsFragment.this.animationTask != null) {
                SettingsFragment.this.animationTask.setSpeedScale(animationSpeedRate / 1000.0);
            }

            SettingsFragment.this.canvasFragment.animationSpeedRate = animationSpeedRate;
        }
    });

    final ImageButton quickButton = (ImageButton) mainView.findViewById(R.id.quickButton);
    quickButton.setOnClickListener(new View.OnClickListener() {

        /**
         * {@inheritDoc}
         */
        public void onClick(View view) {
            int animationSpeedRate = SettingsFragment.this.canvasFragment.animationSpeedRate;

            final int step = (int) Math.floor(Math.log10(animationSpeedRate));
            animationSpeedRate += (int) Math.pow(10, step);
            if (animationSpeedRate > 1000000) {
                animationSpeedRate = 1000000;
            }
            animationSpeedTextEdit.setText(String.format("%g", Double.valueOf(animationSpeedRate / 1000.0))); //$NON-NLS-1$
            if (SettingsFragment.this.animationTask != null) {
                SettingsFragment.this.animationTask.setSpeedScale(animationSpeedRate / 1000.0);
            }

            SettingsFragment.this.canvasFragment.animationSpeedRate = animationSpeedRate;
        }
    });
}

From source file:com.tesora.dve.mysqlapi.repl.messages.MyUserVarLogEvent.java

BigDecimal decodeBinDecimal(ByteBuf cb, int bufferLen, boolean isIntegerPortion) throws PEException {
    BigDecimal decimalPortion = new BigDecimal(0);
    if (bufferLen > 0) {

        ByteBuf decimalPortionBuf = cb.readBytes(bufferLen);

        if (isIntegerPortion) {
            int initialBytes = bufferLen % 4;
            if (initialBytes > 0) {
                long intValue = readValue(decimalPortionBuf, initialBytes);
                decimalPortion = BigDecimal.valueOf(intValue);
            }/*ww  w.  j  a  va 2s  . c o  m*/
        }

        int decimalPortionLen = decimalPortionBuf.readableBytes();

        while (decimalPortionLen > 0) {
            int nextLen = (decimalPortionLen < 4) ? decimalPortionLen : 4;
            long intValue = readValue(decimalPortionBuf, nextLen);

            if (intValue > 0) {
                if (decimalPortion.longValue() == 0) {
                    decimalPortion = decimalPortion.add(BigDecimal.valueOf(intValue));
                } else {
                    int digits = (int) (Math.log10(intValue) + 1);
                    decimalPortion = decimalPortion.movePointRight(digits).add(BigDecimal.valueOf(intValue));
                }
            }

            decimalPortionLen = decimalPortionBuf.readableBytes();
        }
    }
    return decimalPortion;
}

From source file:marytts.util.string.StringUtils.java

public static String[] indexedNameGenerator(String preName, int numFiles, int startIndex, String postName,
        String extension) {/*from   ww  w. jav  a  2 s .  c  om*/
    int numDigits = 0;
    if (numFiles > 0)
        numDigits = (int) Math.floor(Math.log10(startIndex + numFiles - 1));

    return indexedNameGenerator(preName, numFiles, startIndex, postName, extension, numDigits);
}