Skip to content

Commit

Permalink
supports function into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkempire78 committed Nov 20, 2022
1 parent 52e91a7 commit 3804353
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Calculator {
val func: String = equation.substring(startPos, pos)
if (eat('('.code)) {
x = parseExpression()
if (!eat(')'.code)) throw RuntimeException("Missing ')' after argument to $func")
if (!eat(')'.code)) x = parseFactor()
} else {
x = parseFactor()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ class Expression {
val functionsList = listOf("arcos", "arcsin", "arctan", "cos", "sin", "tan", "ln", "log", "exp")
for (function in functionsList) {
val text = cleanCalculation.subSequence(0, i+1).toString()
if (text.endsWith(function) && !text.startsWith(function)) {
if (text.endsWith(function) && text.length != function.length) {
if (text[text.length - function.length - 1] != '*') {
cleanCalculation = cleanCalculation.subSequence(0, i - function.length + 1).toString() +
"*" + function + cleanCalculation.subSequence(i+1, cleanCalculation.length).toString()
cleanCalculationLength ++
break
}
}
Expand Down

0 comments on commit 3804353

Please sign in to comment.