Tabnine Logo
MathLib.floorLog2
Code IndexAdd Tabnine to your IDE (free)

How to use
floorLog2
method
in
javolution.lang.MathLib

Best Java code snippets using javolution.lang.MathLib.floorLog2 (Showing top 8 results out of 315)

origin: org.apache.marmotta/marmotta-commons

/**
 * Returns the largest power of 2 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log2(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog2(double d) {
  if (d <= 0)
    throw new ArithmeticException("Negative number or zero");
  long bits = Double.doubleToLongBits(d);
  int exp = ((int) (bits >> 52)) & 0x7FF;
  if (exp == 0x7FF)
    throw new ArithmeticException("Infinity or NaN");
  if (exp == 0)
    return floorLog2(d * 18014398509481984L) - 54; // 2^54 Exact.       
  return exp - 1023;
}
origin: apache/marmotta

/**
 * Returns the largest power of 2 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log2(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog2(double d) {
  if (d <= 0)
    throw new ArithmeticException("Negative number or zero");
  long bits = Double.doubleToLongBits(d);
  int exp = ((int) (bits >> 52)) & 0x7FF;
  if (exp == 0x7FF)
    throw new ArithmeticException("Infinity or NaN");
  if (exp == 0)
    return floorLog2(d * 18014398509481984L) - 54; // 2^54 Exact.       
  return exp - 1023;
}
origin: javolution/javolution

/**
 * Returns the largest power of 2 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log2(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog2(double d) {
  if (d <= 0)
    throw new ArithmeticException("Negative number or zero");
  long bits = Double.doubleToLongBits(d);
  int exp = ((int) (bits >> 52)) & 0x7FF;
  if (exp == 0x7FF)
    throw new ArithmeticException("Infinity or NaN");
  if (exp == 0)
    return floorLog2(d * 18014398509481984L) - 54;  // 2^54 Exact.       
  return exp - 1023;
}
/**/
origin: org.javolution/javolution-core-java

/**
 * Returns the largest power of 2 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log2(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog2(double d) {
  if (d <= 0)
    throw new ArithmeticException("Negative number or zero");
  long bits = Double.doubleToLongBits(d);
  int exp = ((int) (bits >> 52)) & 0x7FF;
  if (exp == 0x7FF)
    throw new ArithmeticException("Infinity or NaN");
  if (exp == 0)
    return floorLog2(d * 18014398509481984L) - 54; // 2^54 Exact.       
  return exp - 1023;
}
origin: apache/marmotta

/**
 * Returns the largest power of 10 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log10(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog10(double d) {
  int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d));
  double pow10 = MathLib.toDoublePow10(1, guess);
  if ((pow10 <= d) && (pow10 * 10 > d))
    return guess;
  if (pow10 > d)
    return guess - 1;
  return guess + 1;
}
origin: org.apache.marmotta/marmotta-commons

/**
 * Returns the largest power of 10 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log10(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog10(double d) {
  int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d));
  double pow10 = MathLib.toDoublePow10(1, guess);
  if ((pow10 <= d) && (pow10 * 10 > d))
    return guess;
  if (pow10 > d)
    return guess - 1;
  return guess + 1;
}
origin: javolution/javolution

/**
 * Returns the largest power of 10 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log10(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog10(double d) {
  int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d));
  double pow10 = MathLib.toDoublePow10(1, guess);
  if ((pow10 <= d) && (pow10 * 10 > d))
    return guess;
  if (pow10 > d)
    return guess - 1;
  return guess + 1;
}
private static final double LOG2_DIV_LOG10 = 0.3010299956639811952137388947;
origin: org.javolution/javolution-core-java

/**
 * Returns the largest power of 10 that is less than or equal to the
 * the specified positive value.
 *
 * @param d the <code>double</code> number.
 * @return <code>floor(Log10(abs(d)))</code>
 * @throws ArithmeticException if <code>d &lt;= 0<code> or <code>d</code>
 *         is <code>NaN</code> or <code>Infinity</code>.
 **/
public static int floorLog10(double d) {
  int guess = (int) (LOG2_DIV_LOG10 * MathLib.floorLog2(d));
  double pow10 = MathLib.toDoublePow10(1, guess);
  if ((pow10 <= d) && (pow10 * 10 > d))
    return guess;
  if (pow10 > d)
    return guess - 1;
  return guess + 1;
}
javolution.langMathLibfloorLog2

Javadoc

Returns the largest power of 2 that is less than or equal to the the specified positive value.

Popular methods of MathLib

  • min
    Returns the smaller of two long values.
  • sqrt
    Returns the positive square root of the specified value.
  • abs
    Returns the absolute value of the specified long argument.
  • bitLength
    Returns the number of bits in the minimal two's-complement representation of the specified long, exc
  • exp
    Returns #E raised to the specified power.
  • floor
    Returns the largest (closest to positive infinity)double value that is not greater than the argument
  • log
    Returns the natural logarithm (base #E) of the specified value.
  • max
    Returns the greater of two long values.
  • pow
    Returns the value of the first argument raised to the power of the second argument.
  • round
    Returns the closest int to the specified argument.
  • toDoublePow10
    Returns the closest double representation of the specified long number multiplied by a power of ten.
  • toDoublePow2
    Returns the closest double representation of the specified long number multiplied by a power of two.
  • toDoublePow10,
  • toDoublePow2,
  • toLongPow10,
  • _atan,
  • _ieee754_exp,
  • _ieee754_log,
  • asin,
  • atan,
  • digitLength,
  • floorLog10

Popular in Java

  • Creating JSON documents from java classes using gson
  • findViewById (Activity)
  • scheduleAtFixedRate (Timer)
  • notifyDataSetChanged (ArrayAdapter)
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • DataSource (javax.sql)
    An interface for the creation of Connection objects which represent a connection to a database. This
  • Reflections (org.reflections)
    Reflections one-stop-shop objectReflections scans your classpath, indexes the metadata, allows you t
  • CodeWhisperer alternatives
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