MCPcopy Index your code
hub / github.com/RustPython/RustPython / try_float_opt

Method try_float_opt

crates/vm/src/protocol/number.rs:92–101  ·  view source on GitHub ↗
(&self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

90 }
91
92 pub fn try_float_opt(&self, vm: &VirtualMachine) -> Option<PyResult<PyRef<PyFloat>>> {
93 if let Some(float) = self.downcast_ref_if_exact::<PyFloat>(vm) {
94 Some(Ok(float.to_owned()))
95 } else if let Some(f) = self.number().float(vm) {
96 Some(f)
97 } else {
98 self.try_index_opt(vm)
99 .map(|i| Ok(vm.ctx.new_float(int::try_to_float(i?.as_bigint(), vm)?)))
100 }
101 }
102
103 #[inline]
104 pub fn try_float(&self, vm: &VirtualMachine) -> PyResult<PyRef<PyFloat>> {

Callers 6

ceilFunction · 0.80
floorFunction · 0.80
try_floatMethod · 0.80
parse_join_timeoutMethod · 0.80
py_newMethod · 0.80
try_complexMethod · 0.80

Calls 9

try_to_floatFunction · 0.85
floatMethod · 0.80
numberMethod · 0.80
try_index_optMethod · 0.80
as_bigintMethod · 0.80
SomeClass · 0.50
to_ownedMethod · 0.45
mapMethod · 0.45
new_floatMethod · 0.45

Tested by

no test coverage detected