List of usage examples for java.lang Double longBitsToDouble
@HotSpotIntrinsicCandidate public static native double longBitsToDouble(long bits);
From source file:Main.java
public static double bytesBE2double(byte[] b, int off) { return Double.longBitsToDouble(bytesBE2long(b, off)); }
From source file:Main.java
public static double bytesToDoubleBE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongBE(bytes, off)); }
From source file:Main.java
public static double bytesToDoubleLE(byte[] bytes, int off) { return Double.longBitsToDouble(bytesToLongLE(bytes, off)); }
From source file:Main.java
public static double bytesLE2double(byte[] b, int off) { return Double.longBitsToDouble(bytesLE2long(b, off)); }
From source file:Main.java
/** * Returns the floating-point value adjacent to <code>d</code> in * the direction of positive infinity. This method is * semantically equivalent to <code>nextAfter(d, * Double.POSITIVE_INFINITY)</code>; however, a <code>nextUp</code> * implementation may run faster than its equivalent * <code>nextAfter</code> call. * * <p>Special Cases://from w w w .j ava 2 s.c o m * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is positive infinity, the result is * positive infinity. * * <li> If the argument is zero, the result is * <code>Double.MIN_VALUE</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to positive * infinity. * @author Joseph D. Darcy */ public static double nextUp(double d) { if (isNaN(d) || d == Double.POSITIVE_INFINITY) return d; else { d += 0.0d; return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d >= 0.0d) ? +1L : -1L)); } }
From source file:Main.java
/** * Returns the floating-point value adjacent to <code>d</code> in * the direction of negative infinity. This method is * semantically equivalent to <code>nextAfter(d, * Double.NEGATIVE_INFINITY)</code>; however, a * <code>nextDown</code> implementation may run faster than its * equivalent <code>nextAfter</code> call. * * <p>Special Cases:/*from w w w. j a v a2 s.co m*/ * <ul> * <li> If the argument is NaN, the result is NaN. * * <li> If the argument is negative infinity, the result is * negative infinity. * * <li> If the argument is zero, the result is * <code>-Double.MIN_VALUE</code> * * </ul> * * @param d starting floating-point value * @return The adjacent floating-point value closer to negative * infinity. * @author Joseph D. Darcy */ public static double nextDown(double d) { if (isNaN(d) || d == Double.NEGATIVE_INFINITY) return d; else { if (d == 0.0) return -Double.MIN_VALUE; else return Double.longBitsToDouble(Double.doubleToRawLongBits(d) + ((d > 0.0d) ? -1L : +1L)); } }
From source file:Main.java
/** * Get the next machine representable number after a number, moving * in the direction of another number./*from w w w . ja v a2s .com*/ * <p> * If <code>direction</code> is greater than or equal to<code>d</code>, * the smallest machine representable number strictly greater than * <code>d</code> is returned; otherwise the largest representable number * strictly less than <code>d</code> is returned.</p> * <p> * If <code>d</code> is NaN or Infinite, it is returned unchanged.</p> * * @param d base number * @param direction (the only important thing is whether * direction is greater or smaller than d) * @return the next machine representable number in the specified direction * @since 1.2 */ public static double nextAfter(double d, double direction) { // handling of some important special cases if (Double.isNaN(d) || Double.isInfinite(d)) { return d; } else if (d == 0) { return (direction < 0) ? -Double.MIN_VALUE : Double.MIN_VALUE; } // special cases MAX_VALUE to infinity and MIN_VALUE to 0 // are handled just as normal numbers // split the double in raw components long bits = Double.doubleToLongBits(d); long sign = bits & 0x8000000000000000L; long exponent = bits & 0x7ff0000000000000L; long mantissa = bits & 0x000fffffffffffffL; if (d * (direction - d) >= 0) { // we should increase the mantissa if (mantissa == 0x000fffffffffffffL) { return Double.longBitsToDouble(sign | (exponent + 0x0010000000000000L)); } else { return Double.longBitsToDouble(sign | exponent | (mantissa + 1)); } } else { // we should decrease the mantissa if (mantissa == 0L) { return Double.longBitsToDouble(sign | (exponent - 0x0010000000000000L) | 0x000fffffffffffffL); } else { return Double.longBitsToDouble(sign | exponent | (mantissa - 1)); } } }
From source file:com.addthis.bundle.value.DefaultBytes.java
@Override public ValueDouble asDouble() { try {//w w w. j av a 2 s . com return ValueFactory.create(Double.longBitsToDouble(LessBytes.toLong(value))); } catch (Exception ex) { throw new ValueTranslationException(ex); } }
From source file:org.apache.poi.util.LittleEndianInputStream.java
@Override public double readDouble() { return Double.longBitsToDouble(readLong()); }
From source file:Main.java
/** * Returns the size of an ulp of the argument. An ulp of a * <code>double</code> value is the positive distance between this * floating-point value and the <code>double</code> value next * larger in magnitude. Note that for non-NaN <i>x</i>, * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>. * * <p>Special Cases://from w ww.ja va2 s. com * <ul> * <li> If the argument is NaN, then the result is NaN. * <li> If the argument is positive or negative infinity, then the * result is positive infinity. * <li> If the argument is positive or negative zero, then the result is * <code>Double.MIN_VALUE</code>. * <li> If the argument is ±<code>Double.MAX_VALUE</code>, then * the result is equal to 2<sup>971</sup>. * </ul> * * @param d the floating-point value whose ulp is to be returned * @return the size of an ulp of the argument * @author Joseph D. Darcy * @since 1.5 */ public static double ulp(double d) { int exp = getExponent(d); switch (exp) { case DoubleConsts.MAX_EXPONENT + 1: // NaN or infinity return Math.abs(d); // break; case DoubleConsts.MIN_EXPONENT - 1: // zero or subnormal return Double.MIN_VALUE; // break default: assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT; // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x)) exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH - 1); if (exp >= DoubleConsts.MIN_EXPONENT) { return powerOfTwoD(exp); } else { // return a subnormal result; left shift integer // representation of Double.MIN_VALUE appropriate // number of positions return Double.longBitsToDouble( 1L << (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH - 1)))); } // break } }