Skip to content

Commit

Permalink
perf(selector): PolynomialExpression toString
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Apr 7, 2024
1 parent 4943962 commit 80532e4
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ package li.songe.selector.data
data class PolynomialExpression(val a: Int = 0, val b: Int = 1) : ConnectExpression() {

override fun toString(): String {
if (a == 0 && b == 0) return "0"
if (a == 1 && b == 1) return "(n+1)"
if (a > 0 && b > 0) {
if (a == 1) {
return "(n+$b)"
}
return "(${a}n+$b)"
}
if (a < 0 && b > 0) {
if (a == -1) {
return "($b-n)"
}
return "($b${a}n)"
}
if (b == 0) {
if (a == 1) return "n"
return if (a > 0) {
Expand Down

0 comments on commit 80532e4

Please sign in to comment.