1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cmath: added arg, log and complex pow operations

This commit is contained in:
Archan Patkar
2019-07-15 17:44:20 +05:30
committed by Alexander Medvednikov
parent 48c06df5f5
commit 4af58e0925
2 changed files with 91 additions and 0 deletions

View File

@ -160,6 +160,34 @@ pub fn (c Complex) ln() Complex {
}
}
// Complex Log Base 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())
}
// Complex Argument
// Based on
// http://mathworld.wolfram.com/ComplexArgument.html
pub fn (c Complex) arg() f64 {
return math.atan2(c.im,c.re)
}
// Complex raised to Complex Power
// Based on
// http://mathworld.wolfram.com/ComplexExponentiation.html
pub fn (c Complex) cpow(p Complex) Complex {
a := c.arg()
b := math.pow(c.re,2) + math.pow(c.im,2)
d := p.re * a + (1.0/2) * p.im * math.log(b)
t1 := math.pow(b,p.re/2) * math.exp(-p.im*a)
return Complex{
t1 * math.cos(d),
t1 * math.sin(d)
}
}
// Complex Sin
// Based on
// http://www.milefoot.com/math/complex/functionsofi.htm