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

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

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

Math.pow介绍

[英]Returns the closest double approximation of the result of raising x to the power of y.

Special cases:

  • pow((anything), +0.0) = 1.0
  • pow((anything), -0.0) = 1.0
  • pow(x, 1.0) = x
  • pow((anything), NaN) = NaN
  • pow(NaN, (anything except 0)) = NaN
  • pow(+/-(|x| > 1), +infinity) = +infinity
  • pow(+/-(|x| > 1), -infinity) = +0.0
  • pow(+/-(|x| < 1), +infinity) = +0.0
  • pow(+/-(|x| < 1), -infinity) = +infinity
  • pow(+/-1.0 , +infinity) = NaN
  • pow(+/-1.0 , -infinity) = NaN
  • pow(+0.0, (+anything except 0, NaN)) = +0.0
  • pow(-0.0, (+anything except 0, NaN, odd integer)) = +0.0
  • pow(+0.0, (-anything except 0, NaN)) = +infinity
  • pow(-0.0, (-anything except 0, NAN, odd integer)) = +infinity
  • pow(-0.0, (odd integer)) = -pow( +0 , (odd integer) )
  • pow(+infinity, (+anything except 0, NaN)) = +infinity
  • pow(+infinity, (-anything except 0, NaN)) = +0.0
  • pow(-infinity, (anything)) = -pow(0, (-anything))
  • pow((-anything), (integer)) = pow(-1,(integer))*pow(+anything,integer)
  • pow((-anything except 0 and inf), (non-integer)) = NAN
    [中]返回将x提高到y的幂的结果的最接近的双近似值。
    特殊情况:
    *功率((任何),+0.0)=1.0
    *功率((任何事物),-0.0)=1.0
    *功率(x,1.0)=x
    *战俘((任何事),楠)=楠
    *pow(NaN,(除0以外的任何值))=NaN
    *功率(+/-(|x |>1),+infinity)=+infinity
    *功率(+/-(|x |>1),-无穷大)=+0.0
    *功率(+/-(|x |<1),+无穷大)=+0.0
    *功率(+/-(|x |<1),-无穷大)=+无穷大
    *功率(+/-1.0,+无穷大)=NaN
    *功率(+/-1.0,-无穷大)=NaN
    *战力(+0.0,(+除0以外的任何东西,NaN))=+0.0
    *功率(-0.0,(+除0以外的任何值,NaN,奇整数))=+0.0
    *功率(+0.0,(-除0,NaN外的任何东西))=+无穷大
    *pow(-0.0,(-除0以外的任何值,NAN,奇整数))=+无穷大
    *功率(-0.0,(奇数整数))=-pow(+0,(奇数整数))
    *功率(+无穷大,(+除0以外的任何事物,NaN))=+无穷大
    *功率(+无穷大,(-除了0,NaN以外的任何东西))=+0.0
    *pow(-无穷大,(任何事物))=-pow(0,(-任何事物))
    *pow((-anything),(integer))=pow(-1,(integer))*pow(+anything,integer)
    *pow((-除0和inf之外的任何值),(非整数))=NAN

代码示例

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

public float apply (float a) {
    if (a <= 0.5f) return (float)Math.pow(a * 2, power) / 2;
    return (float)Math.pow((a - 1) * 2, power) / (power % 2 == 0 ? -2 : 2) + 1;
  }
}

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

public int reset () {
  low = min;
  high = max;
  current = (low + high) >>> 1;
  if (pot) return (int)Math.pow(2, current);
  if (mod4) return current % 4 == 0 ? current : current + 4 - (current % 4);
  return current;
}

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

public float apply (float a) {
    if (a <= 0.5f) return ((float)Math.pow(value, power * (a * 2 - 1)) - min) * scale / 2;
    return (2 - ((float)Math.pow(value, -power * (a * 2 - 1)) - min) * scale) / 2;
  }
};

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

public Exp (float value, float power) {
  this.value = value;
  this.power = power;
  min = (float)Math.pow(value, -power);
  scale = 1 / (1 - min);
}

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

public Exp (float value, float power) {
  this.value = value;
  this.power = power;
  min = (float)Math.pow(value, -power);
  scale = 1 / (1 - min);
}

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

public int reset () {
  low = min;
  high = max;
  current = (low + high) >>> 1;
  if (pot) return (int)Math.pow(2, current);
  if (mod4) return current % 4 == 0 ? current : current + 4 - (current % 4);
  return current;
}

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

public float apply (float a) {
    if (a <= 0.5f) return ((float)Math.pow(value, power * (a * 2 - 1)) - min) * scale / 2;
    return (2 - ((float)Math.pow(value, -power * (a * 2 - 1)) - min) * scale) / 2;
  }
};

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

public static String humanReadableByteCount(long bytes, boolean si) {
  int unit = si ? 1000 : 1024;
  if (bytes < unit) return bytes + " B";
  int exp = (int) (Math.log(bytes) / Math.log(unit));
  String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
  return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
}

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

public static double round(double value, int places) {
  if (places < 0) throw new IllegalArgumentException();

  long factor = (long) Math.pow(10, places);
  value = value * factor;
  long tmp = Math.round(value);
  return (double) tmp / factor;
}

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

private static int parseInt(String version) {
  int v = 0;
  String[] vArr = version.split("\\.");
  int len = vArr.length;
  for (int i = 0; i < len; i++) {
    v += Integer.parseInt(getDigital(vArr[i])) * Math.pow(10, (len - i - 1) * 2);
  }
  return v;
}

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

private static int parseInt(String version) {
  int v = 0;
  String[] vArr = version.split("\\.");
  int len = vArr.length;
  for (int i = 0; i < len; i++) {
    v += Integer.parseInt(getDigital(vArr[i])) * Math.pow(10, (len - i - 1) * 2);
  }
  return v;
}

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

public float apply (float a) {
    if (a == 0) return 0;
    a = 1 - a;
    return (1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * bounces) * scale);
  }
}

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

public float apply (float a) {
    if (a <= 0.5f) {
      a *= 2;
      return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * bounces) * scale / 2;
    }
    a = 1 - a;
    a *= 2;
    return 1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * bounces) * scale / 2;
  }
}

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

public float apply (float a) {
    if (a >= 0.99) return 1;
    return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * bounces) * scale;
  }
}

代码示例来源:origin: alibaba/druid

public static Histogram makeHistogram(int rangeCount) {
  long[] rangeValues = new long[rangeCount];
  for (int i = 0; i < rangeValues.length; ++i) {
    rangeValues[i] = (long) Math.pow(10, i);
  }
  return new Histogram(rangeValues);
}

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

public float apply (float a) {
    if (a == 0) return 0;
    a = 1 - a;
    return (1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * bounces) * scale);
  }
}

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

public float apply (float a) {
    if (a <= 0.5f) {
      a *= 2;
      return (float)Math.pow(value, power * (a - 1)) * MathUtils.sin(a * bounces) * scale / 2;
    }
    a = 1 - a;
    a *= 2;
    return 1 - (float)Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * bounces) * scale / 2;
  }
}

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

/**
 * Returns the probability that {@linkplain #mightContain(Object)} will erroneously return {@code
 * true} for an object that has not actually been put in the {@code BloomFilter}.
 *
 * <p>Ideally, this number should be close to the {@code fpp} parameter passed in {@linkplain
 * #create(Funnel, int, double)}, or smaller. If it is significantly higher, it is usually the
 * case that too many elements (more than expected) have been put in the {@code BloomFilter},
 * degenerating it.
 *
 * @since 14.0 (since 11.0 as expectedFalsePositiveProbability())
 */
public double expectedFpp() {
 // You down with FPP? (Yeah you know me!) Who's down with FPP? (Every last homie!)
 return Math.pow((double) bits.bitCount() / bitSize(), numHashFunctions);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void SPR9486_floatPowerFloat() {
  Number expectedResult = Math.pow(10.21f, -10.2f);
  ExpressionParser parser = new SpelExpressionParser();
  StandardEvaluationContext context = new StandardEvaluationContext();
  Expression expression = parser.parseExpression("10.21f ^ -10.2f");
  Number result = expression.getValue(context, null, Number.class);
  assertEquals(expectedResult, result);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void SPR9486_floatPowerDouble() {
  Number expectedResult = Math.pow(10.21f, 10.2);
  ExpressionParser parser = new SpelExpressionParser();
  StandardEvaluationContext context = new StandardEvaluationContext();
  Expression expression = parser.parseExpression("10.21f ^ 10.2");
  Number result = expression.getValue(context, null, Number.class);
  assertEquals(expectedResult, result);
}

相关文章