internal static bool TryToFloat(CodeContext context, object /*?*/ value, out double result) { if (value is double d) { result = d; } else if (value is int i) { result = i; } else if (value is BigInteger bi) { result = BigIntegerOps.ToDouble(bi); } else if (TryInvokeFloat(context, value, out result)) { // pass } else if (value is Extensible <double> ed) { result = ed.Value; } else if (value is Extensible <BigInteger> ebi) { result = BigIntegerOps.ToDouble(ebi.Value); } else if (PythonOps.TryToIndex(value, out object ireal)) // Python 3.8: fall back on __index__ { result = ireal switch { int ii => ii, BigInteger bii => BigIntegerOps.ToDouble(bii), _ => throw new InvalidOperationException("Unreachable code") }; } else { return(false); } return(true);