DoubleToInt64Bits() публичный статический Метод

public static DoubleToInt64Bits ( double value ) : long
value double
Результат long
Пример #1
0
        /// <summary>
        /// Computes a hash code for a double value, using the algorithm from
        /// Joshua Bloch's book <i>Effective Java"</i>
        /// </summary>
        /// <param name="value">A hashcode for the double value</param>
        public static int GetHashCode(double value)
        {
            /*
             * From the java language specification, it says:
             *
             * The value of n>>>s is n right-shifted s bit positions with zero-extension.
             * If n is positive, then the result is the same as that of n>>s; if n is
             * negative, the result is equal to that of the expression (n>>s)+(2<<~s) if
             * the type of the left-hand operand is int
             */
            var f = BitConverter.DoubleToInt64Bits(value);

            //if (f > 0)
            return((int)(f ^ (f >> 32)));
            //return (int) (f ^ ((f >> 32) + (2 << ~32)));
        }
Пример #2
0
        /// <summary>
        /// Return HashCode.
        /// </summary>
        public override int GetHashCode()
        {
            long bits0 = BitConverter.DoubleToInt64Bits(_p0.X);

            bits0 ^= BitConverter.DoubleToInt64Bits(_p0.Y) * 31;
            int hash0 = (((int)bits0) ^ ((int)(bits0 >> 32)));

            long bits1 = BitConverter.DoubleToInt64Bits(_p1.X);

            bits1 ^= BitConverter.DoubleToInt64Bits(_p1.Y) * 31;
            int hash1 = (((int)bits1) ^ ((int)(bits1 >> 32)));

            // XOR is supposed to be a good way to combine hashcodes
            return(hash0 ^ hash1);

            //return base.GetHashCode();
        }
Пример #3
0
        public void WriteFloat(double value)
        {
            PrepareValue();

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (value == (float)value)
            {
                //TODO requires careful testing
                _containerStack.IncreaseCurrentContainerLength(5);
                _dataBuffer.WriteByte(TidFloatByte | 4);
                _dataBuffer.WriteUint32(BitConverterEx.SingleToInt32Bits((float)value));
            }
            else
            {
                _containerStack.IncreaseCurrentContainerLength(9);
                _dataBuffer.WriteByte(TidFloatByte | 8);
                _dataBuffer.WriteUint64(BitConverterEx.DoubleToInt64Bits(value));
            }

            FinishValue();
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="x"></param>
 public DoubleBits(double x)
 {
     this.x = x;
     _xBits = BitConverter.DoubleToInt64Bits(x);
 }
Пример #5
0
        private static int GetHashCode(double value)
        {
            var f = BitConverter.DoubleToInt64Bits(value);

            return((int)(f ^ (f >> 32)));
        }
Пример #6
0
        public static unsafe bool IsNaN(double d)
        {
            long bits = BitConverter.DoubleToInt64Bits(d);

            return((bits & 0x7FFFFFFFFFFFFFFF) > 0x7FF0000000000000);
        }
Пример #7
0
 public static unsafe bool IsNegative(double d)
 {
     return(BitConverter.DoubleToInt64Bits(d) < 0);
 }
Пример #8
0
 public Variant(double val)
 {
     _objref = null;
     _flags  = CV_R8;
     _data   = BitConverter.DoubleToInt64Bits(val);
 }
Пример #9
0
        public static unsafe bool IsInfinity(double d)
        {
            var bits = BitConverter.DoubleToInt64Bits(d);

            return((bits & 0x7FFFFFFFFFFFFFFF) == 0x7FF0000000000000);
        }
Пример #10
0
 /// <summary>
 /// 배정밀도 부동 소수점 값을 이용해 <see cref="SecureDouble"/>의 인스턴스를 초기화합니다.
 /// </summary>
 /// <param name="value">배정밀도 부동 소수점 값입니다.</param>
 public SecureDouble(double value)
 {
     this.secureInt64 = BitConverter.DoubleToInt64Bits(value);
 }
Пример #11
0
        public override int GetHashCode()
        {
            float f = this.m_value;

            return(BitConverter.DoubleToInt64Bits(f).GetHashCode());
        }