Skip to content

Commit

Permalink
Merge pull request #18 from TechDevSubhopriyo/master
Browse files Browse the repository at this point in the history
Removed the issue
  • Loading branch information
pH-7 authored Nov 28, 2019
2 parents 2be1bd9 + fa7c9ab commit 5d5fb6d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/simplejavacalculator/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

package simplejavacalculator;

import static java.lang.Double.NaN;
import static java.lang.Math.log;
import static java.lang.Math.log10;
import static java.lang.Math.pow;
Expand All @@ -33,7 +34,11 @@ private Double calculateBiImpl() {
return num2;
}
if (mode == BiOperatorModes.add) {
return num1 + num2;
if (num2 != 0) {
return num1 + num2;
}

return num1;
}
if (mode == BiOperatorModes.minus) {
return num1 - num2;
Expand All @@ -57,7 +62,7 @@ public Double calculateBi(BiOperatorModes newMode, Double num) {
num2 = 0.0;
num1 = num;
mode = newMode;
return Double.NaN;
return NaN;
} else {
num2 = num;
num1 = calculateBiImpl();
Expand All @@ -75,7 +80,7 @@ public Double reset() {
num1 = 0.0;
mode = BiOperatorModes.normal;

return Double.NaN;
return NaN;
}

public Double calculateMono(MonoOperatorModes newMode, Double num) {
Expand All @@ -95,6 +100,13 @@ public Double calculateMono(MonoOperatorModes newMode, Double num) {
return Math.sin(num);
}
if (newMode == MonoOperatorModes.tan) {
if (num == 0 || num % 180 == 0) {
return 0.0;
}
if (num % 90 == 0 && num % 180 != 0)
return NaN;
}

return Math.tan(num);
}
if (newMode == MonoOperatorModes.log) {
Expand All @@ -103,10 +115,10 @@ public Double calculateMono(MonoOperatorModes newMode, Double num) {
if (newMode == MonoOperatorModes.rate) {
return num / 100;
}
if(newMode == MonoOperatorModes.abs){
if (newMode == MonoOperatorModes.abs){
return Math.abs(num);
}

// never reach
throw new Error();
}
Expand Down

0 comments on commit 5d5fb6d

Please sign in to comment.