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

  • Making http post requests using okhttp
  • setScale (BigDecimal)
  • addToBackStack (FragmentTransaction)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • String (java.lang)
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Top 17 Plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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