Tabnine Logo
Math.log
Code IndexAdd Tabnine to your IDE (free)

How to use
log
method
in
java.lang.Math

Best Java code snippets using java.lang.Math.log (Showing top 20 results out of 15,948)

origin: libgdx/libgdx

/** @return the logarithm of value with base a */
static public float log (float a, float value) {
  return (float)(Math.log(value) / Math.log(a));
}
origin: libgdx/libgdx

/** @return the logarithm of value with base a */
static public float log (float a, float value) {
  return (float)(Math.log(value) / Math.log(a));
}
origin: google/guava

/**
 * Returns the base 2 logarithm of a double value.
 *
 * <p>Special cases:
 *
 * <ul>
 *   <li>If {@code x} is NaN or less than zero, the result is NaN.
 *   <li>If {@code x} is positive infinity, the result is positive infinity.
 *   <li>If {@code x} is positive or negative zero, the result is negative infinity.
 * </ul>
 *
 * <p>The computed result is within 1 ulp of the exact result.
 *
 * <p>If the result of this method will be immediately rounded to an {@code int}, {@link
 * #log2(double, RoundingMode)} is faster.
 */
public static double log2(double x) {
 return log(x) / LN_2; // surprisingly within 1 ulp according to tests
}
origin: hankcs/HanLP

/**
 * Log Gamma Function
 *
 * @param Z
 * @return
 */
public static double LogGamma(double Z)
{
  double S = 1.0 + 76.18009173 / Z - 86.50532033 / (Z + 1.0) + 24.01409822 / (Z + 2.0) - 1.231739516 / (Z + 3.0) + 0.00120858003 / (Z + 4.0) - 0.00000536382 / (Z + 5.0);
  double LG = (Z - 0.5) * Math.log(Z + 4.5) - (Z + 4.5) + Math.log(S * 2.50662827465);
  return LG;
}
origin: hankcs/HanLP

protected void toLog()
{
  if (start_probability == null || transition_probability == null || emission_probability == null) return;
  for (int i = 0; i < start_probability.length; i++)
  {
    start_probability[i] = (float) Math.log(start_probability[i]);
    for (int j = 0; j < start_probability.length; j++)
      transition_probability[i][j] = (float) Math.log(transition_probability[i][j]);
    for (int j = 0; j < emission_probability[0].length; j++)
      emission_probability[i][j] = (float) Math.log(emission_probability[i][j]);
  }
}
origin: hankcs/HanLP

  /**
   * 初始化
   * @param outcomeLabels
   */
  public void setLabels(String[] outcomeLabels)
  {
    this.numOutcomes = outcomeLabels.length;
    r = Math.log(1.0 / numOutcomes);
  }
}
origin: stackoverflow.com

// raw estimation how many output digits we will need.
 // This is just enough in cases like BASE-1, and up to
 // 30 digits (for base 2) too much for something like (1,0,0).
 int len = (int) (Math.log(BASE) / Math.log(radix) * digits.length)+1;
 int[] rDigits = new int[len];
 int rIndex = len-1;
 int[] current = digits;
 int quotLen = digits.length;
origin: stackoverflow.com

 public static String humanReadableByteCount(long bytes, boolean si) {
  int unit = si ? 1000 : 1024;
  if (bytes < unit) return bytes + " B";
  int exp = (int) (Math.log(bytes) / Math.log(unit));
  String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
  return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}
origin: google/guava

/**
 * Computes m (total bits of Bloom filter) which is expected to achieve, for the specified
 * expected insertions, the required false positive probability.
 *
 * <p>See http://en.wikipedia.org/wiki/Bloom_filter#Probability_of_false_positives for the
 * formula.
 *
 * @param n expected insertions (must be positive)
 * @param p false positive rate (must be 0 < p < 1)
 */
@VisibleForTesting
static long optimalNumOfBits(long n, double p) {
 if (p == 0) {
  p = Double.MIN_VALUE;
 }
 return (long) (-n * Math.log(p) / (Math.log(2) * Math.log(2)));
}
origin: apache/kafka

public ClusterConnectionStates(long reconnectBackoffMs, long reconnectBackoffMaxMs) {
  this.reconnectBackoffInitMs = reconnectBackoffMs;
  this.reconnectBackoffMaxMs = reconnectBackoffMaxMs;
  this.reconnectBackoffMaxExp = Math.log(this.reconnectBackoffMaxMs / (double) Math.max(reconnectBackoffMs, 1)) / Math.log(RECONNECT_BACKOFF_EXP_BASE);
  this.nodeState = new HashMap<>();
}
origin: google/guava

/**
 * Computes the optimal k (number of hashes per element inserted in Bloom filter), given the
 * expected insertions and total number of bits in the Bloom filter.
 *
 * <p>See http://en.wikipedia.org/wiki/File:Bloom_filter_fp_probability.svg for the formula.
 *
 * @param n expected insertions (must be positive)
 * @param m total number of bits in Bloom filter (must be positive)
 */
@VisibleForTesting
static int optimalNumOfHashFunctions(long n, long m) {
 // (m / n) * log(2), but avoid truncation due to division!
 return Math.max(1, (int) Math.round((double) m / n * Math.log(2)));
}
origin: hankcs/HanLP

private float computeEntropy(Map<Character, int[]> storage)
{
  float sum = 0;
  for (Map.Entry<Character, int[]> entry : storage.entrySet())
  {
    float p = entry.getValue()[0] / (float) frequency;
    sum -= p * Math.log(p);
  }
  return sum;
}
origin: libgdx/libgdx

public BinarySearch (int min, int max, int fuzziness, boolean pot, boolean mod4) {
  if (pot) {
    this.min = (int)(Math.log(MathUtils.nextPowerOfTwo(min)) / Math.log(2));
    this.max = (int)(Math.log(MathUtils.nextPowerOfTwo(max)) / Math.log(2));
  } else if (mod4) {
    this.min = min % 4 == 0 ? min : min + 4 - (min % 4);
    this.max = max % 4 == 0 ? max : max + 4 - (max % 4);
  } else {
    this.min = min;
    this.max = max;
  }
  this.fuzziness = pot ? 0 : fuzziness;
  this.pot = pot;
  this.mod4 = mod4;
}
origin: libgdx/libgdx

public BinarySearch (int min, int max, int fuzziness, boolean pot, boolean mod4) {
  if (pot) {
    this.min = (int)(Math.log(MathUtils.nextPowerOfTwo(min)) / Math.log(2));
    this.max = (int)(Math.log(MathUtils.nextPowerOfTwo(max)) / Math.log(2));
  } else if (mod4) {
    this.min = min % 4 == 0 ? min : min + 4 - (min % 4);
    this.max = max % 4 == 0 ? max : max + 4 - (max % 4);
  } else {
    this.min = min;
    this.max = max;
  }
  this.fuzziness = pot ? 0 : fuzziness;
  this.pot = pot;
  this.mod4 = mod4;
}
origin: hankcs/HanLP

public double computeMutualInformation(String first, String second)
{
  return Math.log(Math.max(Predefine.MIN_PROBABILITY, getPairFrequency(first, second) / (totalPair / 2)) / Math.max(Predefine.MIN_PROBABILITY, (getTermFrequency(first) / totalTerm * getTermFrequency(second) / totalTerm)));
}
origin: hankcs/HanLP

public double computeMutualInformation(PairFrequency pair)
{
  return Math.log(Math.max(Predefine.MIN_PROBABILITY, pair.getValue() / totalPair) / Math.max(Predefine.MIN_PROBABILITY, (CoreDictionary.getTermFrequency(pair.first) / (double) CoreDictionary.totalFrequency * CoreDictionary.getTermFrequency(pair.second) / (double) CoreDictionary.totalFrequency)));
}
origin: prestodb/presto

@Test
public void testLog2()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction("log2(" + doubleValue + ")", DOUBLE, Math.log(doubleValue) / Math.log(2));
  }
  assertFunction("log2(NULL)", DOUBLE, null);
}
origin: prestodb/presto

@Description("natural logarithm")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double ln(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.log(num);
}
origin: google/guava

@GwtIncompatible
public void testResistsHashFloodingOnContains() {
 CallsCounter smallCounter = new CallsCounter();
 List<CountsHashCodeAndEquals> haveSameHashesSmall = createAdversarialInput(10, smallCounter);
 ImmutableSet<?> smallSet = ConstructionPathway.COPY_OF_LIST.create(haveSameHashesSmall);
 long worstCaseOpsSmall = worstCaseQueryOperations(smallSet, smallCounter);
 CallsCounter largeCounter = new CallsCounter();
 List<CountsHashCodeAndEquals> haveSameHashesLarge = createAdversarialInput(15, largeCounter);
 ImmutableSet<?> largeSet = ConstructionPathway.COPY_OF_LIST.create(haveSameHashesLarge);
 long worstCaseOpsLarge = worstCaseQueryOperations(largeSet, largeCounter);
 double ratio = (double) worstCaseOpsLarge / worstCaseOpsSmall;
 int smallSize = haveSameHashesSmall.size();
 int largeSize = haveSameHashesLarge.size();
 assertThat(ratio)
   .named(
     "ratio of equals/hashCode/compareTo operations to worst-case query an ImmutableSet "
       + "of size %s versus size %s",
     haveSameHashesLarge.size(), haveSameHashesSmall.size())
   .isAtMost(2 * Math.log(largeSize) / Math.log(smallSize));
 // We allow up to 2x wobble in the constant factors.
}
origin: prestodb/presto

@InputFunction
public static void input(@AggregationState LongAndDoubleState state, @SqlType(StandardTypes.DOUBLE) double value)
{
  state.setLong(state.getLong() + 1);
  state.setDouble(state.getDouble() + Math.log(value));
}
java.langMathlog

Javadoc

Returns the closest double approximation of the natural logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • log(+0.0) = -infinity
  • log(-0.0) = -infinity
  • log((anything < 0) = NaN
  • log(+infinity) = +infinity
  • log(-infinity) = NaN
  • log(NaN) = NaN

Popular methods of Math

  • min
    Returns the smaller of two long values. That is, the result is the argument closer to the value of L
  • max
    Returns the greater of two long values. That is, the result is the argument closer to the value of L
  • abs
    Returns the absolute value of a long value. If the argument is not negative, the argument is returne
  • round
    Returns the closest int to the argument, with ties rounding up. Special cases: * If the argument is
  • pow
    Returns the value of the first argument raised to the power of the second argument. Special cases: *
  • sqrt
    Returns the correctly rounded positive square root of a double value. Special cases: * If the argume
  • ceil
    Returns the smallest (closest to negative infinity) double value that is greater than or equal to th
  • floor
    Returns the largest (closest to positive infinity) double value that is less than or equal to the ar
  • random
    Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returne
  • sin
    Returns the trigonometric sine of an angle. Special cases: * If the argument is NaN or an infinit
  • cos
    Returns the trigonometric cosine of an angle. Special cases: * If the argument is NaN or an infin
  • exp
    Returns Euler's number e raised to the power of a double value. Special cases: * If the argument
  • cos,
  • exp,
  • toRadians,
  • atan2,
  • log10,
  • acos,
  • tan,
  • toDegrees,
  • atan

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSharedPreferences (Context)
  • getContentResolver (Context)
  • notifyDataSetChanged (ArrayAdapter)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JLabel (javax.swing)
  • XPath (javax.xml.xpath)
    XPath provides access to the XPath evaluation environment and expressions. Evaluation of XPath Expr
  • Top 12 Jupyter Notebook extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now