replace Infinity at Power(x, y) with 0

This commit is contained in:
tibbi 2015-12-26 16:39:01 +01:00
parent 9d7b67ba16
commit e5e64f93fa
1 changed files with 13 additions and 6 deletions

View File

@ -88,6 +88,13 @@ public class MainActivity extends AppCompatActivity {
updateResult(resultValue);
}
private void powerNumbers() {
double resultValue = Math.pow(baseValue, secondValue);
if (Double.isInfinite(resultValue) || Double.isNaN(resultValue))
resultValue = 0;
updateResult(resultValue);
}
private void handleOperation(int operation) {
if (lastKey == operation)
return;
@ -125,6 +132,11 @@ public class MainActivity extends AppCompatActivity {
handleOperation(MODULO);
}
@OnClick(R.id.btn_power)
public void powerClicked() {
handleOperation(POWER);
}
@OnClick(R.id.btn_root)
public void rootClicked() {
getResult();
@ -172,11 +184,6 @@ public class MainActivity extends AppCompatActivity {
lastKey = EQUALS;
}
@OnClick(R.id.btn_power)
public void powerClicked() {
handleOperation(POWER);
}
public void decimalClicked() {
String value = getDisplayedNumber();
if (!value.contains("."))
@ -220,7 +227,7 @@ public class MainActivity extends AppCompatActivity {
moduloNumbers();
break;
case POWER:
updateResult(Math.pow(baseValue, secondValue));
powerNumbers();
break;
default:
break;