Skip to content

Commit e07eb54

Browse files
authored
math.complex: fix handling of the argument to the log() method, replace tests (#25863)
1 parent 473c8e8 commit e07eb54

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

vlib/math/complex/complex.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn (c Complex) ln() Complex {
138138
// Based on
139139
// http://www.milefoot.com/math/complex/summaryops.htm
140140
pub fn (c Complex) log(base Complex) Complex {
141-
return base.ln().divide(c.ln())
141+
return c.ln().divide(base.ln())
142142
}
143143

144144
// Complex Argument

vlib/math/complex/complex_test.v

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -292,25 +292,11 @@ fn test_complex_arg() {
292292
}
293293

294294
fn test_complex_log() {
295-
// Tests were also verified on Wolfram Alpha
296-
mut c1 := cmplx.complex(5, 7)
297-
mut b1 := cmplx.complex(-6, -2)
298-
mut c2 := cmplx.complex(0.232873, -1.413175)
299-
mut result := c1.log(b1)
300-
// Some issue with precision comparison in f64 using == operator hence serializing to string
301-
assert result.str() == c2.str()
302-
c1 = cmplx.complex(-3, 4)
303-
b1 = cmplx.complex(3, -1)
304-
c2 = cmplx.complex(0.152198, -0.409312)
305-
result = c1.log(b1)
306-
// Some issue with precision comparison in f64 using == operator hence serializing to string
307-
assert result.str() == c2.str()
308-
c1 = cmplx.complex(-1, -2)
309-
b1 = cmplx.complex(0, 9)
310-
c2 = cmplx.complex(-0.298243, 1.197981)
311-
result = c1.log(b1)
312-
// Some issue with precision comparison in f64 using == operator hence serializing to string
313-
assert result.str() == c2.str()
295+
a := cmplx.complex(11.22, 33.44)
296+
b := cmplx.complex(55.66, 77.88)
297+
c := a.log(b)
298+
assert c.re.eq_epsilon(0.8032210844549097)
299+
assert c.im.eq_epsilon(0.10605953671930149)
314300
}
315301

316302
fn test_complex_cpow() {

0 commit comments

Comments
 (0)