mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
replace Infinity at Power(x, y) with 0
This commit is contained in:
@@ -88,6 +88,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
updateResult(resultValue);
|
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) {
|
private void handleOperation(int operation) {
|
||||||
if (lastKey == operation)
|
if (lastKey == operation)
|
||||||
return;
|
return;
|
||||||
@@ -125,6 +132,11 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
handleOperation(MODULO);
|
handleOperation(MODULO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OnClick(R.id.btn_power)
|
||||||
|
public void powerClicked() {
|
||||||
|
handleOperation(POWER);
|
||||||
|
}
|
||||||
|
|
||||||
@OnClick(R.id.btn_root)
|
@OnClick(R.id.btn_root)
|
||||||
public void rootClicked() {
|
public void rootClicked() {
|
||||||
getResult();
|
getResult();
|
||||||
@@ -172,11 +184,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
lastKey = EQUALS;
|
lastKey = EQUALS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.btn_power)
|
|
||||||
public void powerClicked() {
|
|
||||||
handleOperation(POWER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void decimalClicked() {
|
public void decimalClicked() {
|
||||||
String value = getDisplayedNumber();
|
String value = getDisplayedNumber();
|
||||||
if (!value.contains("."))
|
if (!value.contains("."))
|
||||||
@@ -220,7 +227,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
moduloNumbers();
|
moduloNumbers();
|
||||||
break;
|
break;
|
||||||
case POWER:
|
case POWER:
|
||||||
updateResult(Math.pow(baseValue, secondValue));
|
powerNumbers();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user