Skip to content

Commit

Permalink
feat: i extension property
Browse files Browse the repository at this point in the history
  • Loading branch information
KatieUmbra committed Nov 10, 2023
1 parent ad93430 commit 59f4d5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
11 changes: 10 additions & 1 deletion src/main/kotlin/compxclib/operators/Operators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,13 @@ operator fun Number.rem(complexNumber: ComplexNumber): ComplexNumber {
@Suppress("unused")
infix fun Number.pow(to: ComplexNumber): ComplexNumber {
return exp(ln(this.toDouble()) * to)
}
}

// Extension for a number
/**
* `i` extension property for numbers that return an imaginary number
* @since Version 1.2
*/
@Suppress("unused")
val Number.i: ComplexNumber
get() = ComplexNumber(0, this)
15 changes: 13 additions & 2 deletions src/test/kotlin/compxclib/FunctionTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package compxclib

import compxclib.enums.SqrtBranch
import kotlin.test.*
import kotlin.math.cosh
import compxclib.functions.*
import compxclib.operators.i
import compxclib.operators.plus
import compxclib.operators.times
import kotlin.math.cosh
import kotlin.test.Test
import kotlin.test.assertEquals

class FunctionTest {

Expand Down Expand Up @@ -116,4 +119,12 @@ class FunctionTest {
arccsch(ComplexNumber(-1, -1))
)
}

@Test
fun iTest() {
assertEquals(
ComplexNumber(5, 6),
5 + 6.i
)
}
}

0 comments on commit 59f4d5c

Please sign in to comment.