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:Main.java

/**
 * Returns the appropriate number of decimals to be used for the provided
 * number.//  w w  w  .j a v a 2  s.  co m
 *
 * @param number
 * @return
 */
public static int getDecimals(float number) {

    float i = roundToNextSignificant(number);
    return (int) Math.ceil(-Math.log10(i)) + 2;
}

From source file:Main.java

/**
 * Rounds the given number to the given number of significant digits. Based on an answer on <a
 * href="http://stackoverflow.com/questions/202302">Stack Overflow</a>.
 */// ww  w .j  ava 2s. co m
public static float roundToOneSignificantFigure(double num) {
    final float d = (float) Math.ceil((float) Math.log10(num < 0 ? -num : num));
    final int power = 1 - (int) d;
    final float magnitude = (float) Math.pow(10, power);
    final long shifted = Math.round(num * magnitude);
    return shifted / magnitude;
}

From source file:Main.java

/**Calculates the estimated distance between the access point based on frequency and signal strength in db. 
 * Based on the Free-space path loss equation at http://en.wikipedia.org/wiki/FSPL
 * /*from www. ja  v  a 2s . co m*/
 * @param levelInDb
 * @param freqInMHz
 * @return
 */
public static double calculateDistance(double levelInDb, double freqInMHz) {
    double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
    return Math.pow(10.0, exp);
}

From source file:Main.java

/**
 * Function to calculate the distance in meters from dbm rssi values.
 * http://rvmiller.com/2013/05/part-1-wifi-based-trilateration-on-android/
 *
 * The function is based on Free Space Path Loss, and may not work with
 * indoor signal propagation.//from w  w w.  j  a  v  a  2  s.c  om
 *
 * @param levelInDb RSSI value.
 * @param freqInMHz Frequency of the sending device.
 * @return Distance in meters.
 */
public static double distanceFSPL(double levelInDb, double freqInMHz) {
    double exp = (27.55 - (20 * Math.log10(freqInMHz)) + Math.abs(levelInDb)) / 20.0;
    return Math.pow(10.0, exp);
}

From source file:Main.java

/**
 * Calculates distance using Free-space path loss. Constant -27.55 is used for calculations, where frequency is in MHz and distance in meters.
 * FSPL(dB) = 20 log(d) + 20 log(f) - 27.55; d distance from the transmitter [m], f signal frequency [MHz]
 *
 * @param level measured RSSI [dBm]//from   w  ww.j  a  v a  2s.c o m
 * @param freq  WiFi frequency [MHz]
 * @return distance from AP [m]
 */
public static double calculateDistance(double level, double freq) {
    double exp = (27.55 - (20 * Math.log10(freq)) + Math.abs(level)) / 20.0;
    return Math.pow(10.0, exp);
}

From source file:Main.java

/**
 * computes the log10 of all values of the passed array
 * @param _arr the array to compute log10 from
 * @return an array containing the log10 of the passed array
 *///from   www  .ja  v  a 2s  . com
public static double[] log10(double[] _arr) {
    double[] res = new double[_arr.length];
    for (int i = 0; i < res.length; i++) {
        if (0.0 == _arr[i]) {
            res[i] = 0;
            continue;
        }
        //         Log.e("ArrayHelper", "before log:"+_arr[i]);
        res[i] = Math.log10(Math.abs(_arr[i]));
        //         Log.e("ArrayHelper", "after log:"+res[i]);
    }
    return res;
}

From source file:Main.java

/**
 * Rounds a number to a given number of significant decimal digits.
 * Note that the number will be left with *only* this number of
 * significant digits regardless of magnitude, e.g. 12345 to 3 digits
 * will be 12300, whereas 0.12345 will be 0.123.
 *
 * @param value the value to round off./*ww w . ja  va2 s .  co m*/
 * @param n     the number of significant decimal digits desired.
 * @return a rounded off number.
 */
public static double roundToSignificantDigits(double value, int n) {
    if (value == 0.0) {
        return 0.0;
    }

    final double d = Math.ceil(Math.log10(value < 0.0 ? -value : value));
    final int power = n - (int) d;

    final double magnitude = Math.pow(10.0, power);
    final long shifted = Math.round(value * magnitude);
    return shifted / magnitude;
}

From source file:Main.java

public static String getReadableSize(long bytes) {
    if (bytes <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(bytes / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

From source file:Main.java

private static double lg2(double value) {
    return Math.log10(value) / Math.log10(2.0);
}

From source file:Main.java

public static int getMatchingThresholdFromString(String value) throws ParseException {
    char percent = new DecimalFormatSymbols().getPercent();
    value = value.replace(percent, ' ');
    Number number = NumberFormat.getNumberInstance().parse(value);
    double parse = number.doubleValue();
    double p = Math.log10(Math.max(Double.MIN_VALUE, Math.min(1, parse / 100)));
    return Math.max(0, (int) Math.round(-12 * p));
}