List of usage examples for java.lang Double longBitsToDouble
@HotSpotIntrinsicCandidate public static native double longBitsToDouble(long bits);
From source file:Main.java
private static double readDouble(byte[] bytes) { long bits = 0; bits = (long) ((((long) bytes[0] << 56) & 0xff00000000000000L) | (((long) bytes[1] << 48) & 0x00ff000000000000L) | (((long) bytes[2] << 40) & 0x0000ff0000000000L) | (((long) bytes[3] << 32) & 0x000000ff00000000L) | (((long) bytes[4] << 24) & 0x00000000ff000000L) | (((long) bytes[5] << 16) & 0x0000000000ff0000L) | (((long) bytes[6] << 8) & 0x000000000000ff00L) | (((long) bytes[7] << 0) & 0x00000000000000ffL)); return Double.longBitsToDouble(bits); }
From source file:Main.java
/** * Reads a "double" value from a byte array at a given offset. The value is * converted to the opposed endian system while reading. * @param data source byte array// w w w .ja v a 2s.com * @param offset starting offset in the byte array * @return the value read */ public static double readSwappedDouble(byte[] data, int offset) { return Double.longBitsToDouble(readSwappedLong(data, offset)); }
From source file:Main.java
/** * Returns a floating-point power of two in the normal range. *///from www .jav a 2s . c o m static double powerOfTwoD(int n) { assert (n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT); return Double.longBitsToDouble( (((long) n + (long) DoubleConsts.EXP_BIAS) << (DoubleConsts.SIGNIFICAND_WIDTH - 1)) & DoubleConsts.EXP_BIT_MASK); }
From source file:Main.java
/** * Converts a sortable <code>long</code> back to a <code>double</code>. * @see #doubleToSortableLong/*from w w w . j a v a 2s.c om*/ */ public static double sortableLongToDouble(long val) { if (val < 0) val ^= 0x7fffffffffffffffL; return Double.longBitsToDouble(val); }
From source file:Main.java
/** * Converts excel's internal RK format into a double value * * @param rk the rk number in bits//w w w . ja v a 2 s .c o m * @return the double representation */ public static double getDouble(int rk) { if ((rk & 0x02) != 0) { int intval = rk >> 2; double value = intval; if ((rk & 0x01) != 0) { value /= 100; } return value; } else { long valbits = (rk & 0xfffffffc); valbits <<= 32; double value = Double.longBitsToDouble(valbits); if ((rk & 0x01) != 0) { value /= 100; } return value; } }
From source file:Main.java
/** * Get a double from the first 8 bytes of a byte array, * in either Big Endian or Little Endian format. * @param b the byte array//ww w. j a v a 2s . co m * @param bigEndian is the byte array Big Endian? * @return the double */ public static final double getDouble(byte[] b, boolean bigEndian) { int i = 0; int j = 0; if (bigEndian) { i = getIntBE(b, 0); j = getIntBE(b, 4); } else { i = getIntLE(b, 4); j = getIntLE(b, 0); } long l = ((long) i << 32) | (j & 0x00000000FFFFFFFFL); return Double.longBitsToDouble(l); }
From source file:Main.java
/** * Do the dirty work of decoding; made a private static method to * facilitate testing the algorithm/*from w w w. j a v a 2 s. c om*/ */ public static double decodeNumber(int number) { long raw_number = number; // mask off the two low-order bits, 'cause they're not part of // the number raw_number = raw_number >> 2; double rvalue = 0; if ((number & 0x02) == 0x02) { // ok, it's just a plain ol' int; we can handle this // trivially by casting rvalue = raw_number; } else { // also trivial, but not as obvious ... left shift the // bits high and use that clever static method in Double // to convert the resulting bit image to a double rvalue = Double.longBitsToDouble(raw_number << 34); } if ((number & 0x01) == 0x01) { // low-order bit says divide by 100, and so we do. Why? // 'cause that's what the algorithm says. Can't fight city // hall, especially if it's the city of Redmond rvalue /= 100; } return rvalue; }
From source file:Main.java
/** * Reads a "double" value from an InputStream. The value is * converted to the opposed endian system while reading. * @param input source InputStream/*from w ww. j a v a 2 s . c o m*/ * @return the value just read * @throws IOException in case of an I/O problem */ public static double readSwappedDouble(InputStream input) throws IOException { return Double.longBitsToDouble(readSwappedLong(input)); }
From source file:Main.java
static void marshalIn(org.omg.CORBA.portable.OutputStream s, TypeCode typeCode, long l, Object o) { switch (typeCode.kind().value()) { case TCKind._tk_null: case TCKind._tk_void: case TCKind._tk_native: // nothing to write break;/*w ww . j a va2 s . c o m*/ case TCKind._tk_short: s.write_short((short) (l & 0xFFFFL)); break; case TCKind._tk_ushort: s.write_ushort((short) (l & 0xFFFFL)); break; case TCKind._tk_enum: case TCKind._tk_long: s.write_long((int) (l & 0xFFFFFFFFL)); break; case TCKind._tk_ulong: s.write_ulong((int) (l & 0xFFFFFFFFL)); break; case TCKind._tk_float: s.write_float(Float.intBitsToFloat((int) (l & 0xFFFFFFFFL))); break; case TCKind._tk_double: s.write_double(Double.longBitsToDouble(l)); break; case TCKind._tk_boolean: if (l == 0) s.write_boolean(false); else s.write_boolean(true); break; case TCKind._tk_char: s.write_char((char) (l & 0xFFFFL)); break; case TCKind._tk_octet: s.write_octet((byte) (l & 0xFFL)); break; case TCKind._tk_any: s.write_any((Any) o); break; case TCKind._tk_TypeCode: s.write_TypeCode((TypeCode) o); break; case TCKind._tk_Principal: s.write_Principal((Principal) o); break; case TCKind._tk_objref: s.write_Object((org.omg.CORBA.Object) o); break; case TCKind._tk_longlong: s.write_longlong(l); break; case TCKind._tk_ulonglong: s.write_ulonglong(l); break; case TCKind._tk_wchar: s.write_wchar((char) (l & 0xFFFFL)); break; case TCKind._tk_string: s.write_string((String) o); break; case TCKind._tk_wstring: s.write_wstring((String) o); break; case TCKind._tk_value: case TCKind._tk_value_box: ((org.omg.CORBA_2_3.portable.OutputStream) s).write_value((Serializable) o); break; case TCKind._tk_fixed: // _REVISIT_ As soon as the java-rtf adds digits and scale parameters to // OutputStream, this check will be unnecessary if (s instanceof CDROutputStream) { try { ((CDROutputStream) s).write_fixed((BigDecimal) o, typeCode.fixed_digits(), typeCode.fixed_scale()); } catch (BadKind badKind) { // impossible } } else { s.write_fixed((BigDecimal) o); } break; case TCKind._tk_struct: case TCKind._tk_union: case TCKind._tk_sequence: case TCKind._tk_array: case TCKind._tk_alias: case TCKind._tk_except: ((Streamable) o)._write(s); break; case TCKind._tk_abstract_interface: ((org.omg.CORBA_2_3.portable.OutputStream) s).write_abstract_interface(o); break; case TCKind._tk_longdouble: // Unspecified for Java default: ORBUtilSystemException wrapper = ORBUtilSystemException.get((com.sun.corba.se.spi.orb.ORB) s.orb(), CORBALogDomains.RPC_PRESENTATION); throw wrapper.typecodeNotSupported(); } }
From source file:Main.java
/** * Converts a 8-byte value into a double * /*from ww w . jav a 2 s . c o m*/ * @param buffer * @return converted value as double */ public static double byte8ToDouble(byte[] buffer) { long lvalue = (((long) (buffer[7]) << 56) + ((long) (buffer[6] & 0xFF) << 48) + ((long) (buffer[5] & 0xFF) << 40) + ((long) (buffer[4] & 0xFF) << 32) + ((long) (buffer[3] & 0xFF) << 24) + ((long) (buffer[2] & 0xFF) << 16) + ((long) (buffer[1] & 0xFF) << 8) + (long) (buffer[0] & 0xFF)); return (Double.longBitsToDouble(lvalue)); }