diff --git a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt index 8f373b8de..79f9e3c35 100644 --- a/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt +++ b/kmath-core/src/commonMain/kotlin/scientifik/kmath/operations/Complex.kt @@ -26,7 +26,7 @@ object ComplexField : ExtendedFieldOperations, Field { Complex(a.re * b.re - a.im * b.im, a.re * b.im + a.im * b.re) override fun divide(a: Complex, b: Complex): Complex { - val norm = b.square + val norm = b.re * b.re + b.im * b.im return Complex((a.re * b.re + a.im * b.im) / norm, (a.re * b.im - a.im * b.re) / norm) } @@ -35,11 +35,11 @@ object ComplexField : ExtendedFieldOperations, Field { override fun cos(arg: Complex): Complex = (exp(-i * arg) + exp(i * arg)) / 2 override fun power(arg: Complex, pow: Number): Complex = - arg.abs.pow(pow.toDouble()) * (cos(pow.toDouble() * arg.theta) + i * sin(pow.toDouble() * arg.theta)) + arg.r.pow(pow.toDouble()) * (cos(pow.toDouble() * arg.theta) + i * sin(pow.toDouble() * arg.theta)) override fun exp(arg: Complex): Complex = exp(arg.re) * (cos(arg.im) + i * sin(arg.im)) - override fun ln(arg: Complex): Complex = ln(arg.abs) + i * atan2(arg.im, arg.re) + override fun ln(arg: Complex): Complex = ln(arg.r) + i * atan2(arg.im, arg.re) operator fun Double.plus(c: Complex) = add(this.toComplex(), c) @@ -62,7 +62,7 @@ data class Complex(val re: Double, val im: Double) : FieldElement { override val objectSize: Int = 16 @@ -82,15 +82,10 @@ data class Complex(val re: Double, val im: Double) : FieldElement