Beispiel #1
0
        public static double Abs(double value)
        {
            const ulong mask = 0x7FFFFFFFFFFFFFFF;
            ulong       raw  = BitConverter.DoubleToUInt64Bits(value);

            return(BitConverter.UInt64BitsToDouble(raw & mask));
        }
Beispiel #2
0
        //
        // Native Declarations
        //
        //| <include path='docs/doc[@for="Double.IsInfinity"]/*' />
        public static bool IsInfinity(double d)
        {
            ulong v = BitConverter.DoubleToUInt64Bits(d);

            return(v == PositiveInfinityAsUInt64 ||
                   v == NegativeInfinityAsUInt64);
        }
Beispiel #3
0
        //| <include path='docs/doc[@for="Double.IsNaN"]/*' />
        public static bool IsNaN(double d)
        {
            // See also Lightning\Src\ClassLibNative\Float\COMFloat::IsNAN
            ulong v = BitConverter.DoubleToUInt64Bits(d);

            return(((v & PositiveInfinityAsUInt64) == v) &&
                   ((v & MantissaAsUInt64) != 0));
        }
Beispiel #4
0
        static bool IBinaryNumber <double> .IsPow2(double value)
        {
            ulong bits = BitConverter.DoubleToUInt64Bits(value);

            uint  exponent    = (uint)(bits >> ExponentShift) & ShiftedExponentMask;
            ulong significand = bits & SignificandMask;

            return((value > 0) &&
                   (exponent != MinExponent) && (exponent != MaxExponent) &&
                   (significand == MinSignificand));
        }
Beispiel #5
0
        //
        // IBinaryNumber
        //

        /// <inheritdoc cref="IBinaryNumber{TSelf}.IsPow2(TSelf)" />
        public static bool IsPow2(double value)
        {
            ulong bits = BitConverter.DoubleToUInt64Bits(value);

            ushort biasedExponent      = ExtractBiasedExponentFromBits(bits);;
            ulong  trailingSignificand = ExtractTrailingSignificandFromBits(bits);

            return((value > 0) &&
                   (biasedExponent != MinBiasedExponent) && (biasedExponent != MaxBiasedExponent) &&
                   (trailingSignificand == MinTrailingSignificand));
        }
Beispiel #6
0
        static double IBitwiseOperators <double, double, double> .operator ~(double value)
        {
            ulong bits = ~BitConverter.DoubleToUInt64Bits(value);

            return(BitConverter.UInt64BitsToDouble(bits));
        }
Beispiel #7
0
        static double IBitwiseOperators <double, double, double> .operator ^(double left, double right)
        {
            ulong bits = BitConverter.DoubleToUInt64Bits(left) ^ BitConverter.DoubleToUInt64Bits(right);

            return(BitConverter.UInt64BitsToDouble(bits));
        }
Beispiel #8
0
        //The hashcode for a double is the absolute value of the integer representation
        //of that double.
        //
        //| <include path='docs/doc[@for="Double.GetHashCode"]/*' />
        public override int GetHashCode()
        {
            long value = unchecked ((long)BitConverter.DoubleToUInt64Bits(m_value));

            return(((int)value) ^ ((int)(value >> 32)));
        }