Skip to content

Commit 59f4d5c

Browse files
committed
feat: i extension property
1 parent ad93430 commit 59f4d5c

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

0 Bytes
Binary file not shown.

src/main/kotlin/compxclib/operators/Operators.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,13 @@ operator fun Number.rem(complexNumber: ComplexNumber): ComplexNumber {
7979
@Suppress("unused")
8080
infix fun Number.pow(to: ComplexNumber): ComplexNumber {
8181
return exp(ln(this.toDouble()) * to)
82-
}
82+
}
83+
84+
// Extension for a number
85+
/**
86+
* `i` extension property for numbers that return an imaginary number
87+
* @since Version 1.2
88+
*/
89+
@Suppress("unused")
90+
val Number.i: ComplexNumber
91+
get() = ComplexNumber(0, this)

src/test/kotlin/compxclib/FunctionTest.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package compxclib
22

33
import compxclib.enums.SqrtBranch
4-
import kotlin.test.*
5-
import kotlin.math.cosh
64
import compxclib.functions.*
5+
import compxclib.operators.i
6+
import compxclib.operators.plus
77
import compxclib.operators.times
8+
import kotlin.math.cosh
9+
import kotlin.test.Test
10+
import kotlin.test.assertEquals
811

912
class FunctionTest {
1013

@@ -116,4 +119,12 @@ class FunctionTest {
116119
arccsch(ComplexNumber(-1, -1))
117120
)
118121
}
122+
123+
@Test
124+
fun iTest() {
125+
assertEquals(
126+
ComplexNumber(5, 6),
127+
5 + 6.i
128+
)
129+
}
119130
}

0 commit comments

Comments
 (0)