private static boolean areEqual(double a, double b) { return Double.doubleToLongBits(a) == Double.doubleToLongBits(b); }
public static long doubleToLongBits (double value) { return Double.doubleToLongBits(value); }
public static long doubleToLongBits (double value) { return Double.doubleToLongBits(value); }
/** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void double2bytes(double v, byte[] b, int off) { long j = Double.doubleToLongBits(v); b[off + 7] = (byte) j; b[off + 6] = (byte) (j >>> 8); b[off + 5] = (byte) (j >>> 16); b[off + 4] = (byte) (j >>> 24); b[off + 3] = (byte) (j >>> 32); b[off + 2] = (byte) (j >>> 40); b[off + 1] = (byte) (j >>> 48); b[off + 0] = (byte) (j >>> 56); }
/** * Returns a suitable hash code for this mutable. * * @return a suitable hash code */ @Override public int hashCode() { final long bits = Double.doubleToLongBits(value); return (int) (bits ^ bits >>> 32); }
/** * to byte array. * * @param v value. * @param b byte array. * @param off array offset. */ public static void double2bytes(double v, byte[] b, int off) { long j = Double.doubleToLongBits(v); b[off + 7] = (byte) j; b[off + 6] = (byte) (j >>> 8); b[off + 5] = (byte) (j >>> 16); b[off + 4] = (byte) (j >>> 24); b[off + 3] = (byte) (j >>> 32); b[off + 2] = (byte) (j >>> 40); b[off + 1] = (byte) (j >>> 48); b[off + 0] = (byte) (j >>> 56); }
/** * Converts a double value to a sortable long. The value is converted by getting their IEEE 754 * floating-point bit layout. Some bits are swapped to be able to compare the result as long. */ public static long doubleToSortableLong(double value) { long bits = Double.doubleToLongBits(value); return bits ^ (bits >> 63) & Long.MAX_VALUE; }
@Override public int hashCode() { // same as hashCode Double.class uses long l = Double.doubleToLongBits(_value); return ((int) l) ^ (int) (l >> 32); } }
public void writeDouble (double v) throws IOException { writeLong(Double.doubleToLongBits(v)); }
public void writeDouble (double v) throws IOException { writeLong(Double.doubleToLongBits(v)); }
/** * <p> * Append a <code>hashCode</code> for a <code>double</code>. * </p> * * @param value * the double to add to the <code>hashCode</code> * @return this */ public HashCodeBuilder append(final double value) { return append(Double.doubleToLongBits(value)); }
Editor putDouble(final Editor edit, final String key, final double value) { return edit.putLong(key, Double.doubleToRawLongBits(value)); } double getDouble(final SharedPreferences prefs, final String key, final double defaultValue) { return Double.longBitsToDouble(prefs.getLong(key, Double.doubleToLongBits(defaultValue))); }
/** * Writes a {@code double} as specified by {@link DataOutputStream#writeDouble(double)}, except * using little-endian byte order. * * @throws IOException if an I/O error occurs */ @Override public void writeDouble(double v) throws IOException { writeLong(Double.doubleToLongBits(v)); }
/** * Converts a "double" value between endian systems. * @param value value to convert * @return the converted value */ public static double swapDouble(final double value) { return Double.longBitsToDouble( swapLong( Double.doubleToLongBits( value ) ) ); }
/** * Writes a "double" value to a byte array at a given offset. The value is * converted to the opposed endian system while writing. * @param data target byte array * @param offset starting offset in the byte array * @param value value to write */ public static void writeSwappedDouble(final byte[] data, final int offset, final double value) { writeSwappedLong( data, offset, Double.doubleToLongBits( value ) ); }
/** * Writes a "double" value to an OutputStream. The value is * converted to the opposed endian system while writing. * @param output target OutputStream * @param value value to write * @throws IOException in case of an I/O problem */ public static void writeSwappedDouble(final OutputStream output, final double value) throws IOException { writeSwappedLong( output, Double.doubleToLongBits( value ) ); }
/** * 将一个双精度浮点数转换位字节数组(8个字节),b[0]存储高位字符,大端 * * @param d 双精度浮点数 * @return 代表双精度浮点数的字节数组 */ public static byte[] doubleToBytes(double d) { return longToBytes(Double.doubleToLongBits(d)); }
static void print(double d) { System.out.printf("%016x\n", Double.doubleToLongBits(d)); } public static void main(String args[]) { double a = 0.5; double b = 0.49999999999999994; print(a); // 3fe0000000000000 print(b); // 3fdfffffffffffff print(a+b); // 3ff0000000000000 print(1.0); // 3ff0000000000000 }
@Test public void nullSafeHashCodeWithDoubleArray() { long bits = Double.doubleToLongBits(8449.65); int expected = 31 * 7 + (int) (bits ^ (bits >>> 32)); bits = Double.doubleToLongBits(9944.923); expected = 31 * expected + (int) (bits ^ (bits >>> 32)); double[] array = {8449.65, 9944.923}; int actual = ObjectUtils.nullSafeHashCode(array); assertEquals(expected, actual); }
private Page buildPage() { BlockBuilder col1 = BIGINT.createBlockBuilder(null, 1); BlockBuilder col2 = DOUBLE.createBlockBuilder(null, 1); BlockBuilder col3 = VARBINARY.createBlockBuilder(null, 1); col1.writeLong(42).closeEntry(); col2.writeLong(doubleToLongBits(43.0)).closeEntry(); col3.writeLong(doubleToLongBits(43.0)).writeLong(1).closeEntry(); return new Page(col1.build(), col2.build(), col3.build()); } }