C / C ++ эквивалент Java doubleToRawLongBits ()

В Java Double.doubleToLongBits () полезен для реализации hashCode () методы.

Я пытаюсь сделать то же самое на C ++ и написать свой собственный метод doubleToRawLongBits () , так как после рыскания через Google я не могу найти подходящую реализацию.

Я могу получить знак и показатель степени из std :: frexp (numbr, & exp) и могу определить знак, но не могу понять, как использовать побитовые операторы для получения эквивалента в Java.

Например, Java Double.doubleToLongBits () возвращает следующее для двойного 3.94:

4616054510065937285

Спасибо за любую помощь.

Грэм

Ниже представлена ​​документация, скопированная и вставленная из 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 &quot;canonical&quot; 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);
5
задан ManuPK 31 October 2011 в 17:26
поделиться