remove everything related to factorials, we dont even have it

This commit is contained in:
tibbi 2020-11-05 23:26:02 +01:00
parent dc97c40b70
commit ae69401aa7
5 changed files with 3 additions and 35 deletions

View File

@ -129,11 +129,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
calculateResult() calculateResult()
} }
private fun handleFactorial() {
baseValue = getDisplayedNumberAsDouble()
calculateResult()
}
private fun calculateResult(update: Boolean = true) { private fun calculateResult(update: Boolean = true) {
if (update) { if (update) {
updateFormula() updateFormula()
@ -185,7 +180,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
handlePercent() handlePercent()
lastKey = tempOp lastKey = tempOp
lastOperation = tempOp lastOperation = tempOp
} else if (lastKey == DIGIT && operation != ROOT && operation != FACTORIAL) { } else if (lastKey == DIGIT && operation != ROOT) {
handleResult() handleResult()
if (inputDisplayedFormula.last() != '+' && if (inputDisplayedFormula.last() != '+' &&
inputDisplayedFormula.last() != '-' && inputDisplayedFormula.last() != '-' &&
@ -205,9 +200,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
if (operation == ROOT) { if (operation == ROOT) {
handleRoot() handleRoot()
resetValue = false resetValue = false
} else if (operation == FACTORIAL) {
handleFactorial()
resetValue = false
} }
} }
@ -318,7 +310,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
PERCENT -> "%" PERCENT -> "%"
POWER -> "^" POWER -> "^"
ROOT -> "" ROOT -> ""
FACTORIAL -> "!"
else -> "" else -> ""
} }

View File

@ -12,7 +12,6 @@ const val ROOT = "root"
const val DECIMAL = "decimal" const val DECIMAL = "decimal"
const val CLEAR = "clear" const val CLEAR = "clear"
const val RESET = "reset" const val RESET = "reset"
const val FACTORIAL = "factorial"
const val NAN = "NaN" const val NAN = "NaN"
const val ZERO = "zero" const val ZERO = "zero"

View File

@ -86,7 +86,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
when (val action = intent.action) { when (val action = intent.action) {
DECIMAL, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, EQUALS, CLEAR, RESET, PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT, FACTORIAL -> myAction(action, context) DECIMAL, ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, EQUALS, CLEAR, RESET, PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT -> myAction(action, context)
else -> super.onReceive(context, intent) else -> super.onReceive(context, intent)
} }
} }
@ -111,7 +111,7 @@ class MyWidgetProvider : AppWidgetProvider(), Calculator {
EQUALS -> calc!!.handleEquals() EQUALS -> calc!!.handleEquals()
CLEAR -> calc!!.handleClear() CLEAR -> calc!!.handleClear()
RESET -> calc!!.handleReset() RESET -> calc!!.handleReset()
PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT, FACTORIAL -> calc!!.handleOperation(action) PLUS, MINUS, MULTIPLY, DIVIDE, PERCENT, POWER, ROOT -> calc!!.handleOperation(action)
} }
} }

View File

@ -1,21 +0,0 @@
package com.simplemobiletools.calculator.operation
import com.simplemobiletools.calculator.operation.base.Operation
import com.simplemobiletools.calculator.operation.base.UnaryOperation
import java.math.BigDecimal
class FactorialOperation(value: BigDecimal) : UnaryOperation(value), Operation {
override fun getResult(): BigDecimal {
return if (value.compareTo(BigDecimal.ZERO) == 0 || value.compareTo(BigDecimal.ONE) == 0 ){
BigDecimal.ONE
} else{
var result = BigDecimal.ONE
val base = value.toInt()
for(i in 1..base){
result = result.multiply(BigDecimal(i))
}
result
}
}
}

View File

@ -15,7 +15,6 @@ object OperationFactory {
PERCENT -> PercentOperation(baseValue, secondValue) PERCENT -> PercentOperation(baseValue, secondValue)
POWER -> PowerOperation(baseValue, secondValue) POWER -> PowerOperation(baseValue, secondValue)
ROOT -> RootOperation(baseValue) ROOT -> RootOperation(baseValue)
FACTORIAL -> FactorialOperation(baseValue)
else -> null else -> null
} }
} }