在Java中,
我正在尝试在C++中做同样的事情,并编写自己的
我可以从
例如,Java的
4616054510065937285
谢谢任何帮助。
Graham
以下是从Double.doubleToRawLongBits()复制并粘贴的文档。
Double.doubleToLongBits()
方法对于实现hashCode()
方法非常有用。我正在尝试在C++中做同样的事情,并编写自己的
doubleToRawLongBits()
方法,因为在通过Google搜索后,我找不到合适的实现方式。我可以从
std::frexp(numbr,&exp)
中获取有效位和指数,并确定符号,但无法弄清楚如何使用位运算符来获得Java等效的结果。例如,Java的
Double.doubleToLongBits()
对于双精度数3.94返回以下值:4616054510065937285
谢谢任何帮助。
Graham
以下是从Double.doubleToRawLongBits()复制并粘贴的文档。
===Java Double.doubleToRawLongBits() description===
/**
* Returns a representation of the specified floating-point value
* according to the IEEE 754 floating-point "double
* format" bit layout, preserving Not-a-Number (NaN) values.
* <p>
* Bit 63 (the bit that is selected by the mask
* <code>0x8000000000000000L</code>) represents the sign of the
* floating-point number. Bits
* 62-52 (the bits that are selected by the mask
* <code>0x7ff0000000000000L</code>) represent the exponent. Bits 51-0
* (the bits that are selected by the mask
* <code>0x000fffffffffffffL</code>) represent the significand
* (sometimes called the mantissa) of the floating-point number.
* <p>
* If the argument is positive infinity, the result is
* <code>0x7ff0000000000000L</code>.
* <p>
* If the argument is negative infinity, the result is
* <code>0xfff0000000000000L</code>.
* <p>
* If the argument is NaN, the result is the <code>long</code>
* integer representing the actual NaN value. Unlike the
* <code>doubleToLongBits</code> method,
* <code>doubleToRawLongBits</code> does not collapse all the bit
* patterns encoding a NaN to a single "canonical" NaN
* value.
* <p>
* In all cases, the result is a <code>long</code> integer that,
* when given to the {@link #longBitsToDouble(long)} method, will
* produce a floating-point value the same as the argument to
* <code>doubleToRawLongBits</code>.
*
* @param value a <code>double</code> precision floating-point number.
* @return the bits that represent the floating-point number.
* @since 1.3
*/
public static native long doubleToRawLongBits(double value);