public static long ConvertDoubleToInt64(double x, FPtoIntegerConversionType t)
        {
            if (t == FPtoIntegerConversionType.CONVERT_NATIVECOMPILERBEHAVIOR)
            {
                return((long)x);
            }

            x = Truncate(x); // truncate (round toward zero)

            // (double)LLONG_MAX cannot be represented exactly as double
            const double llong_max_plus_1 = (double)((ulong)long.MaxValue + 1);

            switch (t)
            {
            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_X86_X64:
            case FPtoIntegerConversionType.CONVERT_BACKWARD_COMPATIBLE:
            case FPtoIntegerConversionType.CONVERT_SENTINEL:
                return((Double.IsNaN(x) || (x < long.MinValue) || (x >= llong_max_plus_1)) ? long.MinValue : (long)x);

            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_ARM32:
                if (x > 0)
                {
                    return((long)CppNativeArm32ConvertDoubleToUInt64(x));
                }
                else
                {
                    return(-(long)CppNativeArm32ConvertDoubleToUInt64(-x));
                }

            case FPtoIntegerConversionType.CONVERT_SATURATING:
                return(Double.IsNaN(x) ? 0 : (x < long.MinValue) ? long.MinValue : (x >= llong_max_plus_1) ? long.MaxValue : (long)x);
            }

            return(0);
        public static uint ConvertDoubleToUInt32(double x, FPtoIntegerConversionType t)
        {
            if (t == FPtoIntegerConversionType.CONVERT_NATIVECOMPILERBEHAVIOR)
            {
                return((uint)x);
            }

            x = Truncate(x); // truncate (round toward zero)
            const double llong_max_plus_1 = (double)((ulong)long.MaxValue + 1);

            switch (t)
            {
            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_X86_X64:
            case FPtoIntegerConversionType.CONVERT_BACKWARD_COMPATIBLE:
                return((Double.IsNaN(x) || (x < long.MinValue) || (x >= llong_max_plus_1)) ? 0 : (uint)(long)x);

            case FPtoIntegerConversionType.CONVERT_SENTINEL:
                return((Double.IsNaN(x) || (x < 0) || (x > uint.MaxValue)) ? uint.MaxValue : (uint)x);

            case FPtoIntegerConversionType.CONVERT_SATURATING:
            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_ARM32:
                return((Double.IsNaN(x) || (x < 0)) ? 0 : (x > uint.MaxValue) ? uint.MaxValue : (uint)x);
            }

            return(0);
        }
        public static int ConvertDoubleToInt32(double x, FPtoIntegerConversionType t)
        {
            if (t == FPtoIntegerConversionType.CONVERT_NATIVECOMPILERBEHAVIOR)
            {
                return((int)x);
            }

            x = Truncate(x); // truncate (round toward zero)

            switch (t)
            {
            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_X86_X64:
            case FPtoIntegerConversionType.CONVERT_BACKWARD_COMPATIBLE:
            case FPtoIntegerConversionType.CONVERT_SENTINEL:
                return((Double.IsNaN(x) || (x < int.MinValue) || (x > int.MaxValue)) ? int.MinValue: (int)x);

            case FPtoIntegerConversionType.CONVERT_SATURATING:
            case FPtoIntegerConversionType.CONVERT_MANAGED_BACKWARD_COMPATIBLE_ARM32:
                return(Double.IsNaN(x) ? 0 : (x < int.MinValue) ? int.MinValue : (x > int.MaxValue) ? int.MaxValue : (int)x);
            }
            return(0);
        }
 public static extern ulong ConvertDoubleToUInt64(double x, FPtoIntegerConversionType t);
 public static extern uint ConvertDoubleToUInt32(double x, FPtoIntegerConversionType t);