Fixed calculated result precision

This commit is contained in:
Sad Ellie 2022-11-20 18:03:58 +04:00
parent cc1c94e86e
commit 7fc6cea761

View File

@ -107,12 +107,13 @@ class MainViewModel @Inject constructor(
// Kotlin doesn't have a multi catch
val calculatedInput = try {
Expressions()
.setPrecision(_userPrefs.value.digitsPrecision)
// Optimal precision, not too low, not too high. Balanced for performance and UX.
.setPrecision(128)
.eval(cleanInput)
} catch (e: Exception) {
// Kotlin doesn't have a multi catch
when (e) {
is ExpressionException, is ArrayIndexOutOfBoundsException, is NumberFormatException -> return mainFlow.value.resultValue
is ExpressionException, is ArrayIndexOutOfBoundsException, is NumberFormatException, is ArithmeticException -> return mainFlow.value.resultValue
else -> throw e
}
}