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

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

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

Math.scalb介绍

[英]Returns d * 2^ scaleFactor. The result may be rounded.
[中]返回d*2^scaleFactor。结果可以四舍五入。

代码示例

代码示例来源:origin: peter-lawrey/Java-Chronicle

value += (modDiv * mod + 4) / 5;
final double d = Math.scalb((double) value, exp);
return negative ? -d : d;

代码示例来源:origin: google/guava

/**
 * Generates a number in [0, 2^numBits) with an exponential distribution. The floor of the log2 of
 * the absolute value of the result is chosen uniformly at random in [0, numBits), and then the
 * result is chosen from those possibilities uniformly at random.
 *
 * <p>Zero is treated as having log2 == 0.
 */
static double randomDouble(int maxExponent) {
 double result = RANDOM_SOURCE.nextDouble();
 result = Math.scalb(result, RANDOM_SOURCE.nextInt(maxExponent + 1));
 return RANDOM_SOURCE.nextBoolean() ? result : -result;
}

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

@Override
 protected ExprEval eval(ExprEval x, ExprEval y)
 {
  return ExprEval.of(Math.scalb(x.asDouble(), y.asInt()));
 }
}

代码示例来源:origin: google/guava

@GwtIncompatible // DoubleMath.log2(double, RoundingMode)
public void testRoundLog2Half() {
 // We don't expect perfect rounding accuracy.
 for (int exp : asList(-1022, -50, -1, 0, 1, 2, 3, 4, 100, 1022, 1023)) {
  for (RoundingMode mode : asList(HALF_EVEN, HALF_UP, HALF_DOWN)) {
   double x = Math.scalb(Math.sqrt(2) + 0.001, exp);
   double y = Math.scalb(Math.sqrt(2) - 0.001, exp);
   if (exp < 0) {
    assertEquals(exp + 1, DoubleMath.log2(x, mode));
    assertEquals(exp, DoubleMath.log2(y, mode));
   } else {
    assertEquals(exp + 1, DoubleMath.log2(x, mode));
    assertEquals(exp, DoubleMath.log2(y, mode));
   }
  }
 }
}

代码示例来源:origin: addthis/stream-lib

for (int j = 0; j < registerSet.count; j++) {
  int val = registerSet.get(j);
  registerSum += Math.scalb(1d, -val);
  if (val == 0) {
    zeros++;

代码示例来源:origin: google/guava

@GwtIncompatible // DoubleMath.log2(double, RoundingMode)
public void testRoundLog2Exact() {
 for (double x : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
  boolean isPowerOfTwo = StrictMath.pow(2.0, DoubleMath.log2(x, FLOOR)) == x;
  try {
   int log2 = DoubleMath.log2(x, UNNECESSARY);
   assertEquals(x, Math.scalb(1.0, log2));
   assertTrue(isPowerOfTwo);
  } catch (ArithmeticException e) {
   assertFalse(isPowerOfTwo);
  }
 }
}

代码示例来源:origin: com.netflix.sstableadaptor/sstable-adaptor-cassandra

@Override
public double size(Token next)
{
  LongToken n = (LongToken) next;
  long v = n.token - token;  // Overflow acceptable and desired.
  double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1.
  return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1.
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

@Override
public double size(Token next)
{
  LongToken n = (LongToken) next;
  long v = n.token - token;  // Overflow acceptable and desired.
  double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1.
  return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1.
}

代码示例来源:origin: jsevellec/cassandra-unit

@Override
public double size(Token next)
{
  LongToken n = (LongToken) next;
  long v = n.token - token;  // Overflow acceptable and desired.
  double d = Math.scalb((double) v, -Long.SIZE); // Scale so that the full range is 1.
  return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1.
}

代码示例来源:origin: com.github.haifengl/smile-math

/**
 * Returns d x 2<sup>scaleFactor</sup> rounded as if performed by a single
 * correctly rounded floating-point multiply to a member of the double value
 * set. 
 */
public static double scalb(double d, int scaleFactor) {
  return java.lang.Math.scalb(d, scaleFactor);
}

代码示例来源:origin: com.github.haifengl/smile-math

/**
 * Returns f x 2<sup>scaleFactor</sup> rounded as if performed by a single
 * correctly rounded floating-point multiply to a member of the float value
 * set.
 */
public static float scalb(float f, int scaleFactor) {
  return java.lang.Math.scalb(f, scaleFactor);
}

代码示例来源:origin: jsevellec/cassandra-unit

public double size(Token next)
  {
    BigIntegerToken n = (BigIntegerToken) next;
    BigInteger v = n.token.subtract(token);  // Overflow acceptable and desired.
    double d = Math.scalb(v.doubleValue(), -127); // Scale so that the full range is 1.
    return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1.
  }
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public double size(Token next)
  {
    BigIntegerToken n = (BigIntegerToken) next;
    BigInteger v = n.token.subtract(token);  // Overflow acceptable and desired.
    double d = Math.scalb(v.doubleValue(), -127); // Scale so that the full range is 1.
    return d > 0.0 ? d : (d + 1.0); // Adjust for signed long, also making sure t.size(t) == 1.
  }
}

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

/** {@inheritDoc} */
public SparseGradient scalb(final int n) {
  final SparseGradient out = new SparseGradient(Math.scalb(value, n), Collections.<Integer, Double> emptyMap());
  for (Map.Entry<Integer, Double> entry : derivatives.entrySet()) {
    out.derivatives.put(entry.getKey(), Math.scalb(entry.getValue(), n));
  }
  return out;
}

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

/** {@inheritDoc}
 * @since 3.2
 */
public DerivativeStructure scalb(final int n) {
  final DerivativeStructure ds = new DerivativeStructure(compiler);
  for (int i = 0; i < ds.data.length; ++i) {
    ds.data[i] = Math.scalb(data[i], n);
  }
  return ds;
}

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

/** {@inheritDoc}
 * @since 3.2
 */
public Decimal64 scalb(final int n) {
  return new Decimal64(Math.scalb(value, n));
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * Returns {@code true} if the given floating point numbers are considered equal.
 * The tolerance factor used in this method is arbitrary and may change in any future version.
 */
static boolean epsilonEquals(final double expected, final double actual) {
  return Math.abs(expected - actual) <= Math.scalb(Math.ulp(expected), 4);
}

代码示例来源:origin: org.python/jython

public static double ldexp(double v, PyObject wObj) {
  long w = getLong(wObj);
  if (w < Integer.MIN_VALUE) {
    w = Integer.MIN_VALUE;
  } else if (w > Integer.MAX_VALUE) {
    w = Integer.MAX_VALUE;
  }
  return exceptInf(Math.scalb(v, (int)w), v);
}

代码示例来源:origin: org.apache.druid/druid-common

@Override
 protected ExprEval eval(ExprEval x, ExprEval y)
 {
  return ExprEval.of(Math.scalb(x.asDouble(), y.asInt()));
 }
}

代码示例来源:origin: org.ballerinalang/ballerina-math

public void execute(Context ctx) {
    double a = ctx.getFloatArgument(0);
    long b = ctx.getIntArgument(0);
    int intVal = ((Long) b).intValue();
    ctx.setReturnValues(new BFloat(Math.scalb(a, intVal)));
  }
}

相关文章