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

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

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

Math.expm1介绍

[英]Returns the closest double approximation of e d - 1. If the argument is very close to 0, it is much more accurate to use expm1(d)+1 than exp(d) (due to cancellation of significant digits). The returned result is within 1 ulp (unit in the last place) of the real result.

For any finite input, the result is not less than -1.0. If the real result is within 0.5 ulp of -1, -1.0 is returned.

Special cases:

  • expm1(+0.0) = +0.0
  • expm1(-0.0) = -0.0
  • expm1(+infinity) = +infinity
  • expm1(-infinity) = -1.0
  • expm1(NaN) = NaN
    [中]返回e d-1的最接近的双近似值。如果参数非常接近于0,则使用expm1(d)+1比exp(d)准确得多(由于有效数字的取消)。返回的结果在实际结果的1 ulp(最后一位的单位)范围内。
    对于任何有限输入,结果不小于-1.0。如果实际结果在-1的0.5 ulp范围内,则返回-1.0。
    特殊情况:
    *expm1(+0.0)=+0.0
    *expm1(-0.0)=-0.0
    *expm1(+无穷大)=+无穷大
    *expm1(-无穷大)=-1.0
    *expm1(NaN)=NaN

代码示例

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

  1. @Override
  2. protected ExprEval eval(double param)
  3. {
  4. return ExprEval.of(Math.expm1(param));
  5. }
  6. }

代码示例来源:origin: DataSketches/sketches-core

  1. /**
  2. * Important note: do not change anything in the following function.
  3. * It has been carefully designed and tested for numerical accuracy.
  4. * In particular, the use of log1p and expm1 is critically important.
  5. * @param kf the value of k as a double
  6. * @param nf the value of n as a double
  7. * @param col the given column
  8. * @return the quantity qnj
  9. */
  10. static double qnj(final double kf, final double nf, final int col) {
  11. final double tmp1 = -1.0 / (kf * (Math.pow(2.0, col)));
  12. final double tmp2 = Math.log1p(tmp1);
  13. return (-1.0 * (Math.expm1(nf * tmp2)));
  14. }

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

  1. /**
  2. * Returns e<sup>x</sup>-1.
  3. */
  4. public static double expm1(double x) {
  5. return java.lang.Math.expm1(x);
  6. }

代码示例来源:origin: net.objecthunter/exp4j

  1. @Override
  2. public double apply(double... args) {
  3. return Math.expm1(args[0]);
  4. }
  5. };

代码示例来源:origin: org.apache.commons/math

  1. /** {@inheritDoc} */
  2. @Override
  3. public RealVector mapExpm1ToSelf() {
  4. for (int i = 0; i < data.length; i++) {
  5. data[i] = Math.expm1(data[i]);
  6. }
  7. return this;
  8. }

代码示例来源:origin: org.apache.commons/math

  1. /** {@inheritDoc} */
  2. @Override
  3. public double value(double d) {
  4. return Math.expm1(d);
  5. }
  6. };

代码示例来源:origin: jpmml/jpmml-evaluator

  1. @Override
  2. public Double evaluate(Number value){
  3. return Math.expm1(value.doubleValue());
  4. }
  5. };

代码示例来源:origin: ca.umontreal.iro/ssj

  1. protected void initArrays(int d) {
  2. double dt, c;
  3. for (int j = 0; j < d; j++) {
  4. dt = t[j+1] - t[j];
  5. c = -Math.expm1(-alpha * dt)*sigma*sigma/(4.0*alpha);
  6. parc[j] = c;
  7. parlam[j] = Math.exp(-alpha * dt) / c;
  8. }
  9. }

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

  1. /**
  2. * {@inheritDoc}
  3. *
  4. * For scale {@code m} and shape {@code s}, the variance is
  5. * {@code (exp(s^2) - 1) * exp(2 * m + s^2)}.
  6. */
  7. public double getNumericalVariance() {
  8. final double s = shape;
  9. final double ss = s * s;
  10. return (Math.expm1(ss)) * Math.exp(2 * scale + ss);
  11. }

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

  1. private double calculateExponential(double result) {
  2. if (!logarithmicWeighting) {
  3. return result;
  4. }
  5. return Math.signum(result) * (Math.expm1(Math.abs(result)));
  6. }

代码示例来源:origin: OpenGamma/Strata

  1. /**
  2. * This is the Taylor expansion of $$\frac{\exp(x)-1}{x}$$ - note for $$|x| > 10^{-10}$$ the expansion is note used .
  3. *
  4. * @param x the value
  5. * @return the result
  6. */
  7. public static double epsilon(double x) {
  8. if (Math.abs(x) > 1e-10) {
  9. return Math.expm1(x) / x;
  10. }
  11. return taylor(x, COEFF1);
  12. }

代码示例来源:origin: ca.umontreal.iro/ssj

  1. private static double invGaver (int n, double u) {
  2. // Gaver-Kafadar normal approximation for the inverse
  3. // \cite{tGAV84a}
  4. double z = NormalDist.inverseF01 (u);
  5. double q = z / (n - 1.0);
  6. double v = q * q * (n - 1.5);
  7. double t = Math.sqrt(n * Math.expm1(v));
  8. if (u >= 0.5)
  9. return t;
  10. else
  11. return -t;
  12. }

代码示例来源:origin: OpenGamma/Strata

  1. /**
  2. * This is the Taylor expansion of the first derivative of $$\frac{\exp(x)-1}{x}$$.
  3. *
  4. * @param x the value
  5. * @return the result
  6. */
  7. public static double epsilonP(double x) {
  8. if (Math.abs(x) > 1e-7) {
  9. return ((x - 1) * Math.expm1(x) + x) / x / x;
  10. }
  11. return taylor(x, COEFF2);
  12. }

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

  1. public static double expm1(double v) {
  2. if (Double.POSITIVE_INFINITY == v) {
  3. return v;
  4. }
  5. double result = Math.expm1(v);
  6. if (Double.isInfinite(result)) {
  7. throw Py.OverflowError(Double.toString(v));
  8. }
  9. return result;
  10. }

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

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

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

  1. @Override
  2. protected ExprEval eval(double param)
  3. {
  4. return ExprEval.of(Math.expm1(param));
  5. }
  6. }

代码示例来源:origin: uk.org.retep.tools/math

  1. @Override
  2. public Object expm1( final MonadicOp op )
  3. throws MathematicsException
  4. {
  5. return Math.expm1( visitNumber( op.getValue() ).doubleValue() );
  6. }

代码示例来源:origin: net.imglib2/imglib2-script

  1. @Override
  2. public final double eval() {
  3. return Math.expm1(a().eval());
  4. }
  5. }

代码示例来源:origin: algorithmfoundry/Foundry

  1. @Override
  2. public double getVariance()
  3. {
  4. double exp1 = this.getLogNormalVariance();
  5. double exp2 = 2.0 * this.getLogNormalMean() + this.getLogNormalVariance();
  6. // (Math.exp(exp1)-1)*Math.exp(exp2)
  7. return (Math.expm1( exp1 ) * Math.exp( exp2 ));
  8. }

代码示例来源:origin: gov.sandia.foundry/gov-sandia-cognition-learning-core

  1. @Override
  2. public double getVariance()
  3. {
  4. double exp1 = this.getLogNormalVariance();
  5. double exp2 = 2.0 * this.getLogNormalMean() + this.getLogNormalVariance();
  6. // (Math.exp(exp1)-1)*Math.exp(exp2)
  7. return (Math.expm1( exp1 ) * Math.exp( exp2 ));
  8. }

相关文章