java.lang.Math.log10()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(5.6k)|赞(0)|评价(0)|浏览(194)

本文整理了Java中java.lang.Math.log10()方法的一些代码示例,展示了Math.log10()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Math.log10()方法的具体详情如下:
包路径:java.lang.Math
类名称:Math
方法名:log10

Math.log10介绍

[英]Returns the closest double approximation of the base 10 logarithm of the argument. The returned result is within 1 ulp (unit in the last place) of the real result.

Special cases:

  • log10(+0.0) = -infinity
  • log10(-0.0) = -infinity
  • log10((anything < 0) = NaN
  • log10(+infinity) = +infinity
  • log10(-infinity) = NaN
  • log10(NaN) = NaN
    [中]返回参数以10为底的对数的最接近的双精度近似值。返回的结果在实际结果的1 ulp(最后一位的单位)范围内。
    特殊情况:
    *log10(+0.0)=-无穷大
    *log10(-0.0)=-无穷大
    *log10((任何小于0的项)=NaN
    *log10(+无穷大)=+无穷大
    *log10(-无穷大)=NaN
    *log10(NaN)=NaN

代码示例

代码示例来源:origin: stackoverflow.com

int n = 1000;
int length = (int)(Math.log10(n)+1);

代码示例来源:origin: hankcs/HanLP

public double weight(int feature, int tf)
  {
    if (feature >= df.length) System.err.println(feature);
    return Math.log10(tf + 1) * (Math.log10((double) numDocs / df[feature] + 1));    // 一种改进的tf*idf计算方式;
  }
}

代码示例来源:origin: mrniko/netty-socketio

public static byte[] longToBytes(long number) {
  // TODO optimize
  int length = (int)(Math.log10(number)+1);
  byte[] res = new byte[length];
  int i = length;
  while (number > 0) {
    res[--i] = (byte) (number % 10);
    number = number / 10;
  }
  return res;
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: neo4j/neo4j

private static int numberOfDigits( long value )
{
  return max( 1, (int)(log10( value ) + 1) );
}

代码示例来源:origin: deathmarine/Luyten

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

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * rounds the given number to the next significant number
 *
 * @param number
 * @return
 */
public static float roundToNextSignificant(double number) {
  if (Double.isInfinite(number) ||
    Double.isNaN(number) ||
    number == 0.0)
    return 0;
  final float d = (float) Math.ceil((float) Math.log10(number < 0 ? -number : number));
  final int pw = 1 - (int) d;
  final float magnitude = (float) Math.pow(10, pw);
  final long shifted = Math.round(number * magnitude);
  return shifted / magnitude;
}

代码示例来源:origin: PhilJay/MPAndroidChart

/**
 * Returns the appropriate number of decimals to be used for the provided
 * number.
 *
 * @param number
 * @return
 */
public static int getDecimals(float number) {
  float i = roundToNextSignificant(number);
  if (Float.isInfinite(i))
    return 0;
  return (int) Math.ceil(-Math.log10(i)) + 2;
}

代码示例来源:origin: prestodb/presto

@SuppressWarnings("NonReproducibleMathCall")
private static int decodeNanos(int nanos)
{
  if (nanos < 0) {
    // This means there is a second VInt present that specifies additional bits of the timestamp.
    // The reversed nanoseconds value is still encoded in this VInt.
    nanos = -nanos - 1;
  }
  int nanosDigits = (int) Math.floor(Math.log10(nanos)) + 1;
  // Reverse the nanos digits (base 10)
  int temp = 0;
  while (nanos != 0) {
    temp *= 10;
    temp += nanos % 10;
    nanos /= 10;
  }
  nanos = temp;
  if (nanosDigits < 9) {
    nanos *= Math.pow(10, 9 - nanosDigits);
  }
  return nanos;
}

代码示例来源:origin: knowm/XChange

private static int numberOfDecimals(BigDecimal value) {
 double d = value.doubleValue();
 return -(int) Math.round(Math.log10(d));
}

代码示例来源:origin: apache/incubator-druid

@Override
 protected ExprEval eval(double param)
 {
  return ExprEval.of(Math.log10(param));
 }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static int getMinorVersion(String version, String prefix) {
  String s = version.substring(prefix.length());
  int major = Integer.parseInt(s);
  s = s.substring((int) (Math.log10(major) + 2));
  return Integer.parseInt(s);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public static int getMinorVersion(String version, String prefix) {
  String s = version.substring(prefix.length());
  int major = Integer.parseInt(s);
  s = s.substring((int) (Math.log10(major) + 2));
  return Integer.parseInt(s);
}

代码示例来源:origin: prestodb/presto

private static long maxPrecision(int numBytes)
{
  return Math.round(Math.floor(Math.log10(Math.pow(2, 8 * numBytes - 1) - 1)));
}

代码示例来源:origin: JetBrains/ideavim

private String lineNumberToString(int lineNumber, @NotNull Editor editor) {
 final int lineCount = editor.getDocument().getLineCount();
 final int digitsCount = (int)Math.ceil(Math.log10(lineCount));
 return StringHelper.leftJustify("" + lineNumber, digitsCount, ' ');
}

代码示例来源:origin: h2oai/h2o-2

protected int pformat_len0( double scale, int lg ) {
 double dx = Math.log10(scale);
 int x = (int)dx;
 if( x >= 0 && PrettyPrint.pow10i(x) != scale ) throw H2O.unimpl();
 int w=1/*blank/sign*/+lg/*compression limits digits*/+1/*dot*/+1/*e*/+1/*neg exp*/+2/*digits of exp*/;
 return w;
}

代码示例来源:origin: neo4j/neo4j

public static DoubleValue log10( AnyValue in )
{
  if ( in instanceof NumberValue )
  {
    return doubleValue( Math.log10( ((NumberValue) in).doubleValue() ) );
  }
  else
  {
    throw needsNumbers( "log10()" );
  }
}

代码示例来源:origin: prestodb/presto

@Description("logarithm to base 10")
@ScalarFunction
@SqlType(StandardTypes.DOUBLE)
public static double log10(@SqlType(StandardTypes.DOUBLE) double num)
{
  return Math.log10(num);
}

代码示例来源:origin: apache/hive

/**
 * Returns the logarithm of "a" with base 10.
 */
@Override
protected DoubleWritable doEvaluate(DoubleWritable a) {
 if (a.get() <= 0.0) {
  return null;
 } else {
  result.set(Math.log10(a.get()));
  return result;
 }
}

代码示例来源:origin: prestodb/presto

@Test
public void testLog10()
{
  for (double doubleValue : DOUBLE_VALUES) {
    assertFunction("log10(" + doubleValue + ")", DOUBLE, Math.log10(doubleValue));
  }
  assertFunction("log10(NULL)", DOUBLE, null);
}

相关文章