(x: PyObjectRef, base: OptionalArg<ArgIntoFloat>, vm: &VirtualMachine)
| 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> { |
no test coverage detected