Skip to content

Commit

Permalink
Fix 'matches integer' comparable
Browse files Browse the repository at this point in the history
Integers and doubles are different: Keep them separate (Until
mathematical comparison)!
Before this fix, 'if 3 matches integer' would fail because it reads '3'
as '3.0'
  • Loading branch information
mcmonkey4eva committed Nov 16, 2013
1 parent d77f552 commit 1251c4a
Showing 1 changed file with 19 additions and 7 deletions.
Expand Up @@ -71,7 +71,9 @@ public void setOperator(Operator operator) {
public void setComparable(String arg) {

// If a Number
if (aH.matchesDouble(arg) || aH.matchesInteger(arg))
if (aH.matchesInteger(arg))
comparable = aH.getIntegerFrom(arg);
else if (aH.matchesDouble(arg))
comparable = aH.getDoubleFrom(arg);

// If a Boolean
Expand Down Expand Up @@ -100,8 +102,10 @@ public void setComparedto(String arg) {
comparedto = arg;

// Comparable is a Number, return Double
else if (comparable instanceof Double) {
if (aH.matchesDouble(arg) || aH.matchesInteger(arg))
else if (comparable instanceof Double || comparable instanceof Integer) {
if (aH.matchesInteger(arg))
comparedto = aH.getIntegerFrom(arg);
else if (aH.matchesDouble(arg))
comparedto = aH.getDoubleFrom(arg);
else {
dB.log(ChatColor.YELLOW + "WARNING! " + ChatColor.WHITE + "Cannot compare NUMBER("
Expand Down Expand Up @@ -144,8 +148,8 @@ else if (comparable instanceof dList) {
compare_as_list();
}

else if (comparable instanceof Double) {
if (comparedto instanceof Double) {
else if (comparable instanceof Double || comparable instanceof Integer) {
if (comparedto instanceof Double || comparedto instanceof Integer) {
compare_as_numbers();
}
}
Expand All @@ -169,8 +173,16 @@ private void compare_as_numbers() {

outcome = false;

Double comparable = (Double) this.comparable;
Double comparedto = (Double) this.comparedto;
Double comparable;
if (this.comparable instanceof Double)
comparable = (Double) this.comparable;
else
comparable = ((Integer) this.comparable).doubleValue();
Double comparedto;
if (this.comparedto instanceof Double)
comparedto = (Double) this.comparedto;
else
comparedto = ((Integer) this.comparedto).doubleValue();

switch(operator) {

Expand Down

0 comments on commit 1251c4a

Please sign in to comment.