java.lang.Double.doubleToLongBits()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(254)

本文整理了Java中java.lang.Double.doubleToLongBits()方法的一些代码示例,展示了Double.doubleToLongBits()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Double.doubleToLongBits()方法的具体详情如下:
包路径:java.lang.Double
类名称:Double
方法名:doubleToLongBits

Double.doubleToLongBits介绍

[英]Returns an integer corresponding to the bits of the given IEEE 754 double precision value. All Not-a-Number (NaN) values are converted to a single NaN representation ( 0x7ff8000000000000L) (compare to #doubleToRawLongBits).
[中]返回与给定IEEE 754双精度值的位对应的整数。所有*非数字(NaN)*值都转换为单个NaN表示(0x7FF80000000000L)(与#doubleToRawLongBits比较)。

代码示例

代码示例来源:origin: google/guava

private static boolean areEqual(double a, double b) {
 return Double.doubleToLongBits(a) == Double.doubleToLongBits(b);
}

代码示例来源:origin: libgdx/libgdx

public static long doubleToLongBits (double value) {
  return Double.doubleToLongBits(value);
}

代码示例来源:origin: libgdx/libgdx

public static long doubleToLongBits (double value) {
  return Double.doubleToLongBits(value);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * 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);
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * 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);
}

代码示例来源:origin: apache/incubator-dubbo

/**
 * 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);
}

代码示例来源:origin: prestodb/presto

/**
 * 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;
}

代码示例来源:origin: prestodb/presto

@Override
  public int hashCode()
  {
    // same as hashCode Double.class uses
    long l = Double.doubleToLongBits(_value);
    return ((int) l) ^ (int) (l >> 32);

  }
}

代码示例来源:origin: libgdx/libgdx

public void writeDouble (double v) throws IOException {
  writeLong(Double.doubleToLongBits(v));
}

代码示例来源:origin: libgdx/libgdx

public void writeDouble (double v) throws IOException {
  writeLong(Double.doubleToLongBits(v));
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * <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));
}

代码示例来源:origin: stackoverflow.com

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)));
}

代码示例来源:origin: google/guava

/**
 * 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));
}

代码示例来源:origin: commons-io/commons-io

/**
 * 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 ) ) );
}

代码示例来源:origin: commons-io/commons-io

/**
 * 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 ) );
}

代码示例来源:origin: commons-io/commons-io

/**
 * 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 ) );
}

代码示例来源:origin: hankcs/HanLP

/**
 * 将一个双精度浮点数转换位字节数组(8个字节),b[0]存储高位字符,大端
 *
 * @param d 双精度浮点数
 * @return 代表双精度浮点数的字节数组
 */
public static byte[] doubleToBytes(double d)
{
  return longToBytes(Double.doubleToLongBits(d));
}

代码示例来源:origin: stackoverflow.com

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
}

代码示例来源:origin: spring-projects/spring-framework

@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);
}

代码示例来源:origin: prestodb/presto

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());
  }
}

相关文章