From e07eb549e4a6a1c827bccafdc69d66e66490c7d7 Mon Sep 17 00:00:00 2001 From: Mike <45243121+tankf33der@users.noreply.github.com> Date: Sun, 30 Nov 2025 16:24:39 +0200 Subject: [PATCH] math.complex: fix handling of the argument to the log() method, replace tests (#25863) --- vlib/math/complex/complex.v | 2 +- vlib/math/complex/complex_test.v | 24 +++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/vlib/math/complex/complex.v b/vlib/math/complex/complex.v index a3c35d214..fad18ca44 100644 --- a/vlib/math/complex/complex.v +++ b/vlib/math/complex/complex.v @@ -138,7 +138,7 @@ pub fn (c Complex) ln() Complex { // Based on // http://www.milefoot.com/math/complex/summaryops.htm pub fn (c Complex) log(base Complex) Complex { - return base.ln().divide(c.ln()) + return c.ln().divide(base.ln()) } // Complex Argument diff --git a/vlib/math/complex/complex_test.v b/vlib/math/complex/complex_test.v index 152678da3..c85e53543 100644 --- a/vlib/math/complex/complex_test.v +++ b/vlib/math/complex/complex_test.v @@ -292,25 +292,11 @@ fn test_complex_arg() { } fn test_complex_log() { - // Tests were also verified on Wolfram Alpha - mut c1 := cmplx.complex(5, 7) - mut b1 := cmplx.complex(-6, -2) - mut c2 := cmplx.complex(0.232873, -1.413175) - mut result := c1.log(b1) - // Some issue with precision comparison in f64 using == operator hence serializing to string - assert result.str() == c2.str() - c1 = cmplx.complex(-3, 4) - b1 = cmplx.complex(3, -1) - c2 = cmplx.complex(0.152198, -0.409312) - result = c1.log(b1) - // Some issue with precision comparison in f64 using == operator hence serializing to string - assert result.str() == c2.str() - c1 = cmplx.complex(-1, -2) - b1 = cmplx.complex(0, 9) - c2 = cmplx.complex(-0.298243, 1.197981) - result = c1.log(b1) - // Some issue with precision comparison in f64 using == operator hence serializing to string - assert result.str() == c2.str() + a := cmplx.complex(11.22, 33.44) + b := cmplx.complex(55.66, 77.88) + c := a.log(b) + assert c.re.eq_epsilon(0.8032210844549097) + assert c.im.eq_epsilon(0.10605953671930149) } fn test_complex_cpow() { -- 2.39.5