Exemple #1
0
 public static void Epsilon()
 {
     Assert.Equal(1.40129846E-45f, float.Epsilon);
     Assert.Equal(0x00000001u, BitConverter.SingleToUInt32Bits(float.Epsilon));
 }
Exemple #2
0
 public static void MaxValue()
 {
     Assert.Equal(3.40282347E+38f, float.MaxValue);
     Assert.Equal(0x7F7FFFFFu, BitConverter.SingleToUInt32Bits(float.MaxValue));
 }
Exemple #3
0
        public static uint ExtractMostSignificantBit(T value)
        {
            if (typeof(T) == typeof(byte))
            {
                uint bits = (byte)(object)value;
                return(bits >> 7);
            }
            else if (typeof(T) == typeof(double))
            {
                ulong bits = BitConverter.DoubleToUInt64Bits((double)(object)value);
                return((uint)(bits >> 63));
            }
            else if (typeof(T) == typeof(short))
            {
                uint bits = (ushort)(short)(object)value;
                return(bits >> 15);
            }
            else if (typeof(T) == typeof(int))
            {
                uint bits = (uint)(int)(object)value;
                return(bits >> 31);
            }
            else if (typeof(T) == typeof(long))
            {
                ulong bits = (ulong)(long)(object)value;
                return((uint)(bits >> 63));
            }
            else if (typeof(T) == typeof(nint))
            {
#if TARGET_64BIT
                ulong bits = (ulong)(nint)(object)value;
                return((uint)(bits >> 63));
#else
                uint bits = (uint)(nint)(object)value;
                return(bits >> 31);
#endif
            }
            else if (typeof(T) == typeof(nuint))
            {
#if TARGET_64BIT
                ulong bits = (ulong)(nuint)(object)value;
                return((uint)(bits >> 63));
#else
                uint bits = (uint)(nuint)(object)value;
                return(bits >> 31);
#endif
            }
            else if (typeof(T) == typeof(sbyte))
            {
                uint bits = (byte)(sbyte)(object)value;
                return(bits >> 7);
            }
            else if (typeof(T) == typeof(float))
            {
                uint bits = BitConverter.SingleToUInt32Bits((float)(object)value);
                return(bits >> 31);
            }
            else if (typeof(T) == typeof(ushort))
            {
                uint bits = (ushort)(object)value;
                return(bits >> 15);
            }
            else if (typeof(T) == typeof(uint))
            {
                uint bits = (uint)(object)value;
                return(bits >> 31);
            }
            else if (typeof(T) == typeof(ulong))
            {
                ulong bits = (ulong)(object)value;
                return((uint)(bits >> 63));
            }
            else
            {
                throw new NotSupportedException(SR.Arg_TypeNotSupported);
            }
        }