/** * Returns the floating point number for the specified <code>double</code> * value (convenience method). * * @param doubleValue the <code>double</code> value. * @return <code>FloatingPoint.valueOf(longValue, 0)</code> */ public static FloatingPoint valueOf(double doubleValue) { if (doubleValue == 0.0) return FloatingPoint.ZERO; if (doubleValue == 1.0) return FloatingPoint.ONE; if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) return FloatingPoint.NaN; // Find the exponent e such as: value == x.xxx * 10^e int e = MathLib.floorLog10(MathLib.abs(doubleValue)) - 18 + 1; // 18 digits significand. long significand = MathLib.toLongPow10(doubleValue, -e); return FloatingPoint.valueOf(significand, e); }
/** * Returns the real number (inexact except for <code>0.0</code>) * corresponding to the specified <code>double</code> value. * The error is derived from the inexact representation of * <code>double</code> values intrinsic to the 64 bits IEEE 754 format. * * @param doubleValue the <code>double</code> value to convert. * @return the corresponding real number. */ public static Real valueOf(double doubleValue) { if (doubleValue == 0.0) return Real.ZERO; if (Double.isNaN(doubleValue) || Double.isInfinite(doubleValue)) return Real.NaN; // Find the exponent e such as: value == x.xxx * 10^e int e = MathLib.floorLog10(MathLib.abs(doubleValue)) - 18 + 1; // 18 digits significand. long significand = MathLib.toLongPow10(doubleValue, -e); int error = (int) MathLib.toLongPow10(Math.ulp(doubleValue), -e) + 1; return Real.valueOf(LargeInteger.valueOf(significand), error, e); }
if (m == 0) return 0L; return toLongPow10(d * 1E16, n - 16);
if (m == 0) return 0L; return toLongPow10(d * 1E16, n - 16);
if (m == 0) return 0L; return toLongPow10(d * 1E16, n - 16);
if (m == 0) return 0L; return toLongPow10(d * 1E16, n - 16);
if (digits < 0) { // Use 16 or 17 digits. long m17 = MathLib.toLongPow10(d, (17 - 1) - e); m = MathLib.toLongPow10(d, (digits - 1) - e);
if (digits < 0) { // Use 16 or 17 digits. long m17 = MathLib.toLongPow10(d, (17 - 1) - e); m = MathLib.toLongPow10(d, (digits - 1) - e);