forked from kscience/kmath
Merge branch 'dev' into dev-0.4
# Conflicts: # kmath-ejml/src/main/kotlin/space/kscience/kmath/ejml/_generated.kt
This commit is contained in:
commit
7d88fb0166
@ -144,12 +144,19 @@ public object ComplexField :
|
|||||||
zero
|
zero
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
exp(pow * ln(arg))
|
exp(pow * ln(arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun power(arg: Complex, pow: Complex): Complex = exp(pow * ln(arg))
|
public fun power(arg: Complex, pow: Complex): Complex = if(arg == zero || arg == (-0.0).toComplex()){
|
||||||
|
if(pow == zero){
|
||||||
|
one
|
||||||
|
} else {
|
||||||
|
zero
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
exp(pow * ln(arg))
|
||||||
|
}
|
||||||
|
|
||||||
public fun Complex.pow(power: Complex): Complex = power(this, power)
|
public fun Complex.pow(power: Complex): Complex = power(this, power)
|
||||||
|
|
||||||
|
@ -71,6 +71,11 @@ internal class ComplexFieldTest {
|
|||||||
(i * 8).let { it.im.toInt() to it.re.toInt() },
|
(i * 8).let { it.im.toInt() to it.re.toInt() },
|
||||||
(Complex(2, 2) pow 2).let { it.im.toInt() to it.re.toInt() })
|
(Complex(2, 2) pow 2).let { it.im.toInt() to it.re.toInt() })
|
||||||
|
|
||||||
|
assertEquals(1.0, Complex(0.0).pow(Complex(0.0)).re, 0.01)
|
||||||
|
assertEquals(1.0, Complex(-0.0).pow(Complex(0.0)).re, 0.01)
|
||||||
|
assertEquals(0.0, Complex(0.0).pow(Complex(2.0)).re, 0.01)
|
||||||
|
assertEquals(0.0, Complex(-0.0).pow(Complex(2.0)).re, 0.01)
|
||||||
|
assertEquals(1.0, Complex(-1.0).pow(Complex(2.0)).re, 0.01)
|
||||||
assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5 + 0 * i).im, 0.01)
|
assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5 + 0 * i).im, 0.01)
|
||||||
assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5).im, 0.01)
|
assertEquals(2.0, power(Complex(-4.0, 0.0), 0.5).im, 0.01)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user