0.1.4 #137
@ -153,7 +153,7 @@ object ComplexField : ExtendedField<Complex>, Norm<Complex, Complex> {
|
||||
*/
|
||||
operator fun Double.times(c: Complex): Complex = Complex(c.re * this, c.im * this)
|
||||
|
||||
override fun norm(arg: Complex): Complex = arg.conjugate * arg
|
||||
override fun norm(arg: Complex): Complex = sqrt(arg.conjugate * arg)
|
||||
|
||||
override fun symbol(value: String): Complex = if (value == "i") i else super.symbol(value)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package scientifik.kmath.operations
|
||||
|
||||
import kotlin.math.*
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.abs
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
@ -64,4 +65,9 @@ internal class ComplexFieldTest {
|
||||
ComplexField { i * 8 }.let { it.im.toInt() to it.re.toInt() },
|
||||
ComplexField { Complex(2, 2) pow 2 }.let { it.im.toInt() to it.re.toInt() })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNorm() {
|
||||
assertEquals(2.toComplex(), ComplexField { norm(2 * i) })
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user