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

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

本文整理了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

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

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

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

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

  1. @Override
  2. protected ExprEval eval(ExprEval x, ExprEval y)
  3. {
  4. return ExprEval.of(Math.scalb(x.asDouble(), y.asInt()));
  5. }
  6. }

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

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

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

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

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

  1. @GwtIncompatible // DoubleMath.log2(double, RoundingMode)
  2. public void testRoundLog2Exact() {
  3. for (double x : POSITIVE_FINITE_DOUBLE_CANDIDATES) {
  4. boolean isPowerOfTwo = StrictMath.pow(2.0, DoubleMath.log2(x, FLOOR)) == x;
  5. try {
  6. int log2 = DoubleMath.log2(x, UNNECESSARY);
  7. assertEquals(x, Math.scalb(1.0, log2));
  8. assertTrue(isPowerOfTwo);
  9. } catch (ArithmeticException e) {
  10. assertFalse(isPowerOfTwo);
  11. }
  12. }
  13. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. /** {@inheritDoc}
  2. * @since 3.2
  3. */
  4. public DerivativeStructure scalb(final int n) {
  5. final DerivativeStructure ds = new DerivativeStructure(compiler);
  6. for (int i = 0; i < ds.data.length; ++i) {
  7. ds.data[i] = Math.scalb(data[i], n);
  8. }
  9. return ds;
  10. }

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

  1. /** {@inheritDoc}
  2. * @since 3.2
  3. */
  4. public Decimal64 scalb(final int n) {
  5. return new Decimal64(Math.scalb(value, n));
  6. }

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

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

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

  1. public static double ldexp(double v, PyObject wObj) {
  2. long w = getLong(wObj);
  3. if (w < Integer.MIN_VALUE) {
  4. w = Integer.MIN_VALUE;
  5. } else if (w > Integer.MAX_VALUE) {
  6. w = Integer.MAX_VALUE;
  7. }
  8. return exceptInf(Math.scalb(v, (int)w), v);
  9. }

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

  1. @Override
  2. protected ExprEval eval(ExprEval x, ExprEval y)
  3. {
  4. return ExprEval.of(Math.scalb(x.asDouble(), y.asInt()));
  5. }
  6. }

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

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

相关文章