本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.NAN_VALUE_CONVERSION属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.NAN_VALUE_CONVERSION属性的具体用法?Java LocalizedFormats.NAN_VALUE_CONVERSION怎么用?Java LocalizedFormats.NAN_VALUE_CONVERSION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.NAN_VALUE_CONVERSION属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BigFraction
/**
* Create a fraction given the double value.
* <p>
* This constructor behaves <em>differently</em> from
* {@link #BigFraction(double, double, int)}. It converts the double value
* exactly, considering its internal bits representation. This works for all
* values except NaN and infinities and does not requires any loop or
* convergence threshold.
* </p>
* <p>
* Since this conversion is exact and since double numbers are sometimes
* approximated, the fraction created may seem strange in some cases. For example,
* calling <code>new BigFraction(1.0 / 3.0)</code> does <em>not</em> create
* the fraction 1/3, but the fraction 6004799503160661 / 18014398509481984
* because the double number passed to the constructor is not exactly 1/3
* (this number cannot be stored exactly in IEEE754).
* </p>
* @see #BigFraction(double, double, int)
* @param value the double value to convert to a fraction.
* @exception MathIllegalArgumentException if value is NaN or infinite
*/
public BigFraction(final double value) throws MathIllegalArgumentException {
if (Double.isNaN(value)) {
throw new MathIllegalArgumentException(LocalizedFormats.NAN_VALUE_CONVERSION);
}
if (Double.isInfinite(value)) {
throw new MathIllegalArgumentException(LocalizedFormats.INFINITE_VALUE_CONVERSION);
}
// compute m and k such that value = m * 2^k
final long bits = Double.doubleToLongBits(value);
final long sign = bits & 0x8000000000000000L;
final long exponent = bits & 0x7ff0000000000000L;
long m = bits & 0x000fffffffffffffL;
if (exponent != 0) {
// this was a normalized number, add the implicit most significant bit
m |= 0x0010000000000000L;
}
if (sign != 0) {
m = -m;
}
int k = ((int) (exponent >> 52)) - 1075;
while (((m & 0x001ffffffffffffeL) != 0) && ((m & 0x1) == 0)) {
m >>= 1;
++k;
}
if (k < 0) {
numerator = BigInteger.valueOf(m);
denominator = BigInteger.ZERO.flipBit(-k);
} else {
numerator = BigInteger.valueOf(m).multiply(BigInteger.ZERO.flipBit(k));
denominator = BigInteger.ONE;
}
}