From ebd0352cfc39ca94d9b3b5f88f4c19be4d835af8 Mon Sep 17 00:00:00 2001 From: Tetramad Date: Mon, 25 Oct 2021 11:45:03 +0900 Subject: [PATCH] Fix math.log10 to pass some failed tests Now math.log10 with less than or equal to zero should raise ValueError with "math domain error" message if `x` fit in f64 --- stdlib/src/math.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/src/math.rs b/stdlib/src/math.rs index 889cd1671..7c51f0d73 100644 --- a/stdlib/src/math.rs +++ b/stdlib/src/math.rs @@ -166,7 +166,12 @@ mod math { #[pyfunction] fn log10(x: ArgIntoFloat, vm: &VirtualMachine) -> PyResult { - call_math_func!(log10, x, vm) + let x = x.to_f64(); + if x.is_nan() || x > 0.0_f64 { + Ok(x.log10()) + } else { + Err(vm.new_value_error("math domain error".to_owned())) + } } #[pyfunction]