diff --git a/app/src/main/java/com/darkempire78/opencalculator/Calculator.kt b/app/src/main/java/com/darkempire78/opencalculator/Calculator.kt index 184d7170..a6c8d1fd 100644 --- a/app/src/main/java/com/darkempire78/opencalculator/Calculator.kt +++ b/app/src/main/java/com/darkempire78/opencalculator/Calculator.kt @@ -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()