本文整理汇总了Java中org.apache.commons.math3.util.FastMath.getExponent方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.getExponent方法的具体用法?Java FastMath.getExponent怎么用?Java FastMath.getExponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.FastMath
的用法示例。
在下文中一共展示了FastMath.getExponent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doubleValue
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
* <p>
* Gets the fraction as a {@code double}. This calculates the fraction as
* the numerator divided by denominator.
* </p>
*
* @return the fraction as a {@code double}
* @see java.lang.Number#doubleValue()
*/
@Override
public double doubleValue() {
double result = numerator.doubleValue() / denominator.doubleValue();
if (Double.isNaN(result)) {
// Numerator and/or denominator must be out of range:
// Calculate how far to shift them to put them in range.
int shift = FastMath.max(numerator.bitLength(),
denominator.bitLength()) - FastMath.getExponent(Double.MAX_VALUE);
result = numerator.shiftRight(shift).doubleValue() /
denominator.shiftRight(shift).doubleValue();
}
return result;
}
示例2: floatValue
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
* <p>
* Gets the fraction as a {@code float}. This calculates the fraction as
* the numerator divided by denominator.
* </p>
*
* @return the fraction as a {@code float}.
* @see java.lang.Number#floatValue()
*/
@Override
public float floatValue() {
float result = numerator.floatValue() / denominator.floatValue();
if (Double.isNaN(result)) {
// Numerator and/or denominator must be out of range:
// Calculate how far to shift them to put them in range.
int shift = FastMath.max(numerator.bitLength(),
denominator.bitLength()) - FastMath.getExponent(Float.MAX_VALUE);
result = numerator.shiftRight(shift).floatValue() /
denominator.shiftRight(shift).floatValue();
}
return result;
}
示例3: hypot
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public SparseGradient hypot(final SparseGradient y) {
if (Double.isInfinite(value) || Double.isInfinite(y.value)) {
return createConstant(Double.POSITIVE_INFINITY);
} else if (Double.isNaN(value) || Double.isNaN(y.value)) {
return createConstant(Double.NaN);
} else {
final int expX = FastMath.getExponent(value);
final int expY = FastMath.getExponent(y.value);
if (expX > expY + 27) {
// y is negligible with respect to x
return abs();
} else if (expY > expX + 27) {
// x is negligible with respect to y
return y.abs();
} else {
// find an intermediate scale to avoid both overflow and underflow
final int middleExp = (expX + expY) / 2;
// scale parameters without losing precision
final SparseGradient scaledX = scalb(-middleExp);
final SparseGradient scaledY = y.scalb(-middleExp);
// compute scaled hypotenuse
final SparseGradient scaledH =
scaledX.multiply(scaledX).add(scaledY.multiply(scaledY)).sqrt();
// remove scaling
return scaledH.scalb(middleExp);
}
}
}
示例4: getExponent
import org.apache.commons.math3.util.FastMath; //导入方法依赖的package包/类
/**
* Return the exponent of the instance value, removing the bias.
* <p>
* For double numbers of the form 2<sup>x</sup>, the unbiased
* exponent is exactly x.
* </p>
* @return exponent for instance in IEEE754 representation, without bias
*/
public int getExponent() {
return FastMath.getExponent(data[0]);
}