Skip to content

Commit

Permalink
fix #107
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkempire78 committed Dec 8, 2022
1 parent 3978edc commit 5a016c1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/src/main/java/com/darkempire78/opencalculator/Calculator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ class Calculator {
} else {
x = Double.NaN
}
if (eat('^'.code)) x = x.pow(parseFactor()) // exponentiation
if (eat('^'.code)) {
x = x.pow(parseFactor())
// To fix sqrt(2)^2 = 2
val decimal = x.toInt()
val fractional = x - decimal
if (fractional < 1.0E-14) {
x = decimal.toDouble()
}
} // exponentiation
return x
}
}.parse()
Expand Down

0 comments on commit 5a016c1

Please sign in to comment.