Skip to content

Commit 5a016c1

Browse files
committed
fix #107
1 parent 3978edc commit 5a016c1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/src/main/java/com/darkempire78/opencalculator/Calculator.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ class Calculator {
192192
} else {
193193
x = Double.NaN
194194
}
195-
if (eat('^'.code)) x = x.pow(parseFactor()) // exponentiation
195+
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
196204
return x
197205
}
198206
}.parse()

0 commit comments

Comments
 (0)