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

Function log2

crates/stdlib/src/math.rs:131–147  ·  view source on GitHub ↗
(x: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

129
130 #[pyfunction]
131 fn log2(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<f64> {
132 // Handle BigInt specially for large values (only for actual int type, not float)
133 if let Some(i) = x.downcast_ref::<PyInt>() {
134 return pymath::math::log2_bigint(i.as_bigint()).map_err(|err| match err {
135 pymath::Error::EDOM => vm.new_value_error("expected a positive input"),
136 _ => pymath_exception(err, vm),
137 });
138 }
139 let val = x.try_float(vm)?.to_f64();
140 pymath::math::log2(val).map_err(|err| match err {
141 pymath::Error::EDOM => vm.new_value_error(format!(
142 "expected a positive input, got {}",
143 super::float_repr(val)
144 )),
145 _ => pymath_exception(err, vm),
146 })
147 }
148
149 #[pyfunction]
150 fn log10(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<f64> {

Callers 1

GenDotMethod · 0.90

Calls 4

pymath_exceptionFunction · 0.85
as_bigintMethod · 0.80
to_f64Method · 0.80
try_floatMethod · 0.80

Tested by 1

GenDotMethod · 0.72