Exemplo n.º 1
0
        internal static byte GetByte(object?o)
        {
            var index = PythonOps.Index(o);

            return(index switch {
                int i => i.ToByteChecked(),
                BigInteger bi => bi.ToByteChecked(),
                _ => throw new InvalidOperationException() // unreachable
            });
Exemplo n.º 2
0
        public static BigInteger __round__(BigInteger self, object ndigits) {
            var index = PythonOps.Index(ndigits);
            switch (index) {
                case int i:
                    return __round__(self, i);

                case BigInteger bi:
                    return __round__(self, bi);
            }

            throw PythonOps.RuntimeError(
                "Unreachable code was reached. "
                + "PythonOps.Index is guaranteed to either throw or return an integral value.");
        }
Exemplo n.º 3
0
        public static object __new__(PythonType cls, string s, object @base)
        {
            switch (PythonOps.Index(@base))
            {
            case int i:
                return(__new__(cls, s, i));

            case BigInteger bi:
                try {
                    return(__new__(cls, s, (int)bi));
                } catch (OverflowException) {
                    return(__new__(cls, s, int.MaxValue));
                }

            default:
                throw new InvalidOperationException();
            }
        }