| 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> { |