-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: term inverse + simple expression
- Loading branch information
1 parent
18d5ab6
commit 77388a4
Showing
7 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
exact-numbers/src/main/kotlin/xyz/lbres/exactnumbers/expressions/expression/Expression.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package xyz.lbres.exactnumbers.expressions.expression | ||
|
||
abstract class Expression : Number() { | ||
abstract operator fun unaryMinus(): Expression | ||
abstract operator fun unaryPlus(): Expression | ||
abstract fun inverse(): Expression | ||
|
||
// open operator fun plus(other: Expression): Expression = AdditiveExpression(constMultiSetOf(this, other)) | ||
// open operator fun minus(other: Expression): Expression = AdditiveExpression(constMultiSetOf(this, -other)) | ||
// open operator fun times(other: Expression): Expression = MultiplicativeExpression(constMultiSetOf(this, other)) | ||
// open operator fun div(other: Expression): Expression = MultiplicativeExpression(constMultiSetOf(this, other.inverse())) | ||
|
||
override fun toByte(): Byte = 0 // TODO | ||
override fun toChar(): Char = '0' // TODO | ||
override fun toShort(): Short = 0 // TODO | ||
override fun toInt(): Int = 0 // TODO | ||
override fun toLong(): Long = 0 // TODO | ||
override fun toFloat(): Float = 0f // TODO | ||
override fun toDouble(): Double = 0.0 // TODO | ||
} |
16 changes: 16 additions & 0 deletions
16
...numbers/src/main/kotlin/xyz/lbres/exactnumbers/expressions/expression/SimpleExpression.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package xyz.lbres.exactnumbers.expressions.expression | ||
|
||
import xyz.lbres.exactnumbers.expressions.term.Term | ||
|
||
/** | ||
* Expression consisting of a single term | ||
*/ | ||
internal class SimpleExpression(private val term: Term) : Expression() { | ||
override fun unaryMinus(): Expression = SimpleExpression(-term) | ||
|
||
override fun unaryPlus(): Expression = this | ||
|
||
override fun inverse(): Expression = SimpleExpression(term.inverse()) | ||
|
||
override fun equals(other: Any?): Boolean = other is SimpleExpression && term == other.term | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...ers/src/test/kotlin/xyz/lbres/exactnumbers/expressions/expression/SimpleExpressionTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package xyz.lbres.exactnumbers.expressions.expression | ||
|
||
import kotlin.test.Test | ||
|
||
class SimpleExpressionTest { | ||
@Test | ||
fun testConstructor() { | ||
// TODO | ||
} | ||
|
||
@Test | ||
fun testUnaryMinus() { | ||
// TODO | ||
} | ||
|
||
@Test | ||
fun testUnaryPlus() { | ||
// TODO | ||
} | ||
|
||
@Test | ||
fun testInverse() { | ||
// TODO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters