We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3978edc commit 5a016c1Copy full SHA for 5a016c1
app/src/main/java/com/darkempire78/opencalculator/Calculator.kt
@@ -192,7 +192,15 @@ class Calculator {
192
} else {
193
x = Double.NaN
194
}
195
- if (eat('^'.code)) x = x.pow(parseFactor()) // exponentiation
+ if (eat('^'.code)) {
196
+ x = x.pow(parseFactor())
197
+ // To fix sqrt(2)^2 = 2
198
+ val decimal = x.toInt()
199
+ val fractional = x - decimal
200
+ if (fractional < 1.0E-14) {
201
+ x = decimal.toDouble()
202
+ }
203
+ } // exponentiation
204
return x
205
206
}.parse()
0 commit comments