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

Function log

crates/stdlib/src/math.rs:94–123  ·  view source on GitHub ↗
(x: PyObjectRef, base: OptionalArg<ArgIntoFloat>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

92
93 #[pyfunction]
94 fn log(x: PyObjectRef, base: OptionalArg<ArgIntoFloat>, vm: &VirtualMachine) -> PyResult<f64> {
95 let base = base.into_option().map(|v| v.into_float());
96 // Check base first for proper error messages
97 if let Some(b) = base {
98 if b <= 0.0 {
99 return Err(vm.new_value_error(format!(
100 "expected a positive input, got {}",
101 super::float_repr(b)
102 )));
103 }
104 if b == 1.0 {
105 return Err(vm.new_value_error("math domain error"));
106 }
107 }
108 // Handle BigInt specially for large values (only for actual int type, not float)
109 if let Some(i) = x.downcast_ref::<PyInt>() {
110 return pymath::math::log_bigint(i.as_bigint(), base).map_err(|err| match err {
111 pymath::Error::EDOM => vm.new_value_error("expected a positive input"),
112 _ => pymath_exception(err, vm),
113 });
114 }
115 let val = x.try_float(vm)?.to_f64();
116 pymath::math::log(val, base).map_err(|err| match err {
117 pymath::Error::EDOM => vm.new_value_error(format!(
118 "expected a positive input, got {}",
119 super::float_repr(val)
120 )),
121 _ => pymath_exception(err, vm),
122 })
123 }
124
125 #[pyfunction]
126 fn log1p(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult<f64> {

Callers 4

logistic_kernelFunction · 0.90
sigmoid_kernelFunction · 0.90
overlapMethod · 0.90
_normal_dist_inv_cdfFunction · 0.90

Calls 8

pymath_exceptionFunction · 0.85
into_optionMethod · 0.80
into_floatMethod · 0.80
as_bigintMethod · 0.80
to_f64Method · 0.80
try_floatMethod · 0.80
ErrClass · 0.50
mapMethod · 0.45

Tested by

no test coverage detected